@nebutra/agents 2.0.0 → 3.0.0

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/README.md CHANGED
@@ -67,7 +67,7 @@ orchestrator.registerAgent(
67
67
  new VercelAIAgent({ id: "assistant", name: "Assistant", description: "Helpful", model: "openai/gpt-5.5", instructions: "..." }),
68
68
  );
69
69
 
70
- const ctx = createAgentContext("org_123", "user_456");
70
+ const ctx = createAgentContext({ tenantId: "org_123", product: "app" }, "user_456");
71
71
  const response = await orchestrator.chat("Hello", ctx);
72
72
  // → response.usage tracks tokens for billing
73
73
  ```
@@ -1,4 +1,4 @@
1
- import { c as AgentConfig, A as AgentMessage, a as AgentContext, b as AgentResponse } from './types-BytC-HfQ.js';
1
+ import { c as AgentConfig, A as AgentMessage, a as AgentContext, b as AgentResponse } from './types-CRbPsTpE.js';
2
2
 
3
3
  /**
4
4
  * BaseAgent — abstract agent with memory, usage tracking, and tenant scoping.
@@ -107,6 +107,7 @@ var BaseAgent = class {
107
107
  const durationMs = Date.now() - startTime;
108
108
  const usage = {
109
109
  tenantId: context.tenantId,
110
+ product: context.product,
110
111
  userId: context.userId,
111
112
  agentId: this.config.id,
112
113
  model: this.config.model,
@@ -145,6 +146,7 @@ var BaseAgent = class {
145
146
  const creditCost = Math.max(1, Math.ceil(totalTokens / 1e4));
146
147
  await deductCredits({
147
148
  organizationId: event.tenantId,
149
+ product: event.product,
148
150
  amount: creditCost,
149
151
  description: `Agent execution: ${event.model}`
150
152
  });
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { B as BaseAgent } from './agent-DDGWuUpe.js';
1
+ import { B as BaseAgent } from './agent-DyyFxZf-.js';
2
2
  export { AgentsEnv, AgentsEnvSchema, FallbackProviderName, getAgentsEnv, isLangfuseConfigured } from './env.js';
3
3
  export { CreateFallbackModelOptions, EmbeddingFallbackOptions, FallbackResult, buildSystemWithCache, filterAvailableProviders, isRetryableError, runEmbedWithFallback, runWithFallback, withAnthropicCacheControl } from './fallback.js';
4
4
  export { GenerationCallOptions, GenerationContext, GenerationModality, GenerationProvider, GenerationResult, ImageGenerationRequest, VideoGenerationRequest, _resetGenerationRegistry, generateImage, generateVideo, listGenerationProviders, mockGenerationProvider, registerGenerationProvider } from './generation/index.js';
5
- import { A as AgentMessage, O as OrchestratorConfig, a as AgentContext, b as AgentResponse, R as RouterConfig, c as AgentConfig } from './types-BytC-HfQ.js';
6
- export { d as AgentTool, e as AgentUsageEvent, M as MemoryConfig, T as TokenUsage, f as ToolCallResult } from './types-BytC-HfQ.js';
5
+ import { A as AgentMessage, O as OrchestratorConfig, a as AgentContext, b as AgentResponse, R as RouterConfig, c as AgentConfig } from './types-CRbPsTpE.js';
6
+ export { d as AgentTool, e as AgentUsageEvent, M as MemoryConfig, T as TokenUsage, f as ToolCallResult } from './types-CRbPsTpE.js';
7
7
  export { TelemetryMetadata, buildTelemetryConfig, flushTelemetry, initLangfuse } from './observability.js';
8
8
  export { EmbedOptions, GenerateOptions, GenerateStructuredResult, OPENAI_MAX_PROPERTY_NAME_LENGTH, assertSafeOpenAIJsonPayload, configure, embed, embedMany, findOversizedPropertyName, generateStructured, generateText, getConfig, streamText, validateStructured } from './sdk/index.js';
9
9
  export { BUILT_IN_TOOLS, databaseQueryTool, knowledgeBaseTool, webSearchTool } from './tools.js';
@@ -153,15 +153,21 @@ declare class AgentRouter {
153
153
  /**
154
154
  * Create a fully-populated AgentContext.
155
155
  * Generates a random conversationId when none is provided.
156
+ *
157
+ * `scope` names the tenant and the product whose balance the run spends:
158
+ * balances are per product, so a run cannot be billed without one.
156
159
  */
157
- declare function createAgentContext(tenantId: string, userId: string, conversationId?: string, metadata?: Record<string, unknown>): AgentContext;
160
+ declare function createAgentContext(scope: {
161
+ tenantId: string;
162
+ product: string;
163
+ }, userId: string, conversationId?: string, metadata?: Record<string, unknown>): AgentContext;
158
164
  /**
159
165
  * Validate that a tenant has remaining quota for agent execution.
160
166
  *
161
167
  * Returns `{ allowed: true, remaining: -1 }` (unlimited) by default.
162
168
  * Integrate with @nebutra/billing entitlements for production usage.
163
169
  */
164
- declare function checkAgentQuota(tenantId: string): Promise<{
170
+ declare function checkAgentQuota(tenantId: string, product: string): Promise<{
165
171
  allowed: boolean;
166
172
  remaining: number;
167
173
  }>;
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ import {
62
62
  clearMemory,
63
63
  getMemory,
64
64
  saveMemory
65
- } from "./chunk-RDOFKRI6.js";
65
+ } from "./chunk-HAAM3SJN.js";
66
66
 
67
67
  // src/context.ts
68
68
  var MAX_BIO_CHARS = 2e3;
@@ -229,18 +229,19 @@ ${agentList}`,
229
229
  };
230
230
 
231
231
  // src/tenant.ts
232
- function createAgentContext(tenantId, userId, conversationId, metadata) {
232
+ function createAgentContext(scope, userId, conversationId, metadata) {
233
233
  return {
234
- tenantId,
234
+ tenantId: scope.tenantId,
235
+ product: scope.product,
235
236
  userId,
236
237
  conversationId: conversationId ?? crypto.randomUUID(),
237
238
  ...metadata !== void 0 ? { metadata } : {}
238
239
  };
239
240
  }
240
- async function checkAgentQuota(tenantId) {
241
+ async function checkAgentQuota(tenantId, product) {
241
242
  try {
242
243
  const { getCreditBalance } = await import("@nebutra/billing/credits");
243
- const balance = await getCreditBalance(tenantId);
244
+ const balance = await getCreditBalance(tenantId, product);
244
245
  if (balance.balance > 0) {
245
246
  return { allowed: true, remaining: balance.balance };
246
247
  }
@@ -276,7 +277,7 @@ var AgentOrchestrator = class {
276
277
  }
277
278
  /** Route a message to the best agent and execute. */
278
279
  async chat(message, context) {
279
- await this.assertQuota(context.tenantId);
280
+ await this.assertQuota(context.tenantId, context.product);
280
281
  const agentConfigs = [...this.agents.values()].map((a) => a.config);
281
282
  const agentId = await this.router.route(message, agentConfigs, context, this.defaultAgentId);
282
283
  const agent = this.agents.get(agentId);
@@ -287,8 +288,8 @@ var AgentOrchestrator = class {
287
288
  return agent.run(messages, context);
288
289
  }
289
290
  /** Check tenant quota before execution. */
290
- async assertQuota(tenantId) {
291
- const { allowed } = await checkAgentQuota(tenantId);
291
+ async assertQuota(tenantId, product) {
292
+ const { allowed } = await checkAgentQuota(tenantId, product);
292
293
  if (!allowed) {
293
294
  throw new Error(`Tenant "${tenantId}" has exceeded agent execution quota`);
294
295
  }
@@ -1,5 +1,5 @@
1
- import { B as BaseAgent } from '../agent-DDGWuUpe.js';
2
- import { c as AgentConfig } from '../types-BytC-HfQ.js';
1
+ import { B as BaseAgent } from '../agent-DyyFxZf-.js';
2
+ import { c as AgentConfig } from '../types-CRbPsTpE.js';
3
3
 
4
4
  /**
5
5
  * LangChain.js agent adapter — stub.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BaseAgent
3
- } from "../chunk-RDOFKRI6.js";
3
+ } from "../chunk-HAAM3SJN.js";
4
4
 
5
5
  // src/providers/langchain.ts
6
6
  var LangChainAgent = class extends BaseAgent {
@@ -1,5 +1,5 @@
1
- import { B as BaseAgent } from '../agent-DDGWuUpe.js';
2
- import { A as AgentMessage, a as AgentContext, b as AgentResponse } from '../types-BytC-HfQ.js';
1
+ import { B as BaseAgent } from '../agent-DyyFxZf-.js';
2
+ import { A as AgentMessage, a as AgentContext, b as AgentResponse } from '../types-CRbPsTpE.js';
3
3
 
4
4
  /**
5
5
  * Vercel AI SDK agent adapter.
@@ -12,7 +12,7 @@ import "../chunk-HVLFZW6E.js";
12
12
  import "../chunk-FCXWOXII.js";
13
13
  import {
14
14
  BaseAgent
15
- } from "../chunk-RDOFKRI6.js";
15
+ } from "../chunk-HAAM3SJN.js";
16
16
 
17
17
  // src/providers/vercel-ai.ts
18
18
  var VercelAIAgent = class extends BaseAgent {
package/dist/tools.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as AgentTool } from './types-BytC-HfQ.js';
1
+ import { d as AgentTool } from './types-CRbPsTpE.js';
2
2
 
3
3
  /**
4
4
  * Built-in tool registry for agents.
@@ -30,6 +30,8 @@ interface AgentTool {
30
30
  }
31
31
  interface AgentContext {
32
32
  readonly tenantId: string;
33
+ /** The product whose balance pays for this run (ADR 2026-09-27 product wallets). */
34
+ readonly product: string;
33
35
  readonly userId: string;
34
36
  readonly conversationId: string;
35
37
  readonly metadata?: Record<string, unknown>;
@@ -75,6 +77,7 @@ interface RouterConfig {
75
77
  }
76
78
  interface AgentUsageEvent {
77
79
  readonly tenantId: string;
80
+ readonly product: string;
78
81
  readonly userId: string;
79
82
  readonly agentId: string;
80
83
  readonly model: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nebutra/agents",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Nebutra AI runtime: multi-agent orchestration + Vercel AI SDK helpers (absorbed @nebutra/ai-sdk in 1.0.0)",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -86,9 +86,9 @@
86
86
  "langfuse": "^3.38.20",
87
87
  "langfuse-vercel": "^3.38.20",
88
88
  "zod": "^4.3.6",
89
- "@nebutra/billing": "2.0.0",
90
- "@nebutra/cache": "2.0.0",
91
- "@nebutra/logger": "2.0.0"
89
+ "@nebutra/billing": "3.0.0",
90
+ "@nebutra/cache": "3.0.0",
91
+ "@nebutra/logger": "3.0.0"
92
92
  },
93
93
  "devDependencies": {
94
94
  "@types/node": "^25.9.1",