@yuva-devlab/sdk 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yuva Devlab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,202 @@
1
+ 'use strict';
2
+
3
+ var agentCore = require('@yuva-devlab/agent-core');
4
+ var aiClient = require('@yuva-devlab/ai-client');
5
+ var billing = require('@yuva-devlab/billing');
6
+ var events = require('@yuva-devlab/events');
7
+ var logger$1 = require('@yuva-devlab/logger');
8
+ var rag = require('@yuva-devlab/rag');
9
+ var semanticCache = require('@yuva-devlab/semantic-cache');
10
+ var errors = require('@yuva-devlab/errors');
11
+ var resilience = require('@yuva-devlab/resilience');
12
+
13
+ // src/constants/sdk.constants.ts
14
+ var DEFAULT_CLIENT_TIMEOUT_MS = 3e4;
15
+ var DEFAULT_GATEWAY_URL = "http://localhost:3000";
16
+ var SDK_VERSION = "0.1.0";
17
+ var logger = logger$1.loggerWithConfig(new logger$1.Logger("DevLabClient"));
18
+ var DevLabClient = class {
19
+ ai;
20
+ embedder;
21
+ cache;
22
+ tools;
23
+ vectorStore;
24
+ chunker;
25
+ events;
26
+ billing;
27
+ gatewayUrl;
28
+ tenantId;
29
+ timeoutMs;
30
+ /**
31
+ * Initializes the unified DevLab platform client.
32
+ *
33
+ * @param config - Platform client options
34
+ */
35
+ constructor(config = {}) {
36
+ this.gatewayUrl = config.gatewayUrl ?? DEFAULT_GATEWAY_URL;
37
+ this.tenantId = config.tenantId;
38
+ this.timeoutMs = config.timeoutMs ?? DEFAULT_CLIENT_TIMEOUT_MS;
39
+ this.ai = config.aiProvider ?? aiClient.createDefaultProvider();
40
+ this.embedder = config.embeddingProvider ?? new rag.MockEmbeddingProvider();
41
+ this.chunker = new rag.TextChunker();
42
+ this.vectorStore = new rag.InMemoryVectorStore(this.embedder);
43
+ this.cache = new semanticCache.SemanticCache(this.embedder);
44
+ this.tools = new agentCore.ToolRegistry();
45
+ const pricing = new billing.DynamicPricingResolver({
46
+ loader: config.pricingLoader
47
+ });
48
+ const ledger = new billing.CostLedger();
49
+ const enforcer = new billing.BudgetEnforcer(ledger);
50
+ const counter = new billing.TokenCounter({ pricingResolver: pricing });
51
+ this.billing = { counter, ledger, enforcer, pricing };
52
+ this.events = config.eventBus ?? new events.InMemoryEventBus();
53
+ logger.debug("[constructor] DevLabClient initialized", {
54
+ gatewayUrl: this.gatewayUrl,
55
+ tenantId: this.tenantId
56
+ });
57
+ }
58
+ /**
59
+ * Completes an LLM prompt request.
60
+ *
61
+ * @param request - LLM completion request
62
+ * @returns Model response
63
+ */
64
+ async complete(request) {
65
+ logger.debug("[complete] Executing AI completion via unified client", {
66
+ model: request.model
67
+ });
68
+ return this.ai.complete(request);
69
+ }
70
+ /**
71
+ * Streams token chunks incrementally.
72
+ *
73
+ * @param request - LLM completion request
74
+ * @returns Async iterable yielding token deltas
75
+ */
76
+ async *stream(request) {
77
+ yield* this.ai.stream(request);
78
+ }
79
+ /**
80
+ * Executes a vector similarity search across ingested document chunks.
81
+ *
82
+ * @param query - Search parameters
83
+ * @returns Scored document chunks
84
+ */
85
+ async search(query) {
86
+ logger.debug("[search] Executing RAG search via unified client", {
87
+ query: query.query
88
+ });
89
+ return this.vectorStore.search(query);
90
+ }
91
+ /**
92
+ * Executes a registered agent tool by name.
93
+ *
94
+ * @param toolName - Registered tool slug
95
+ * @param input - Tool input arguments
96
+ * @param ctx - Tool execution context
97
+ * @returns Tool execution result
98
+ */
99
+ async executeTool(toolName, input, ctx) {
100
+ logger.debug("[executeTool] Executing registered tool", { toolName });
101
+ const tool = this.tools.getOrThrow(toolName);
102
+ return tool.execute(input, {
103
+ executionId: ctx.executionId,
104
+ tenantId: ctx.tenantId ?? this.tenantId
105
+ });
106
+ }
107
+ /**
108
+ * Helper to compile a system prompt with tool documentation.
109
+ */
110
+ compilePrompt(template, variables = {}) {
111
+ return agentCore.compilePrompt({
112
+ template,
113
+ variables,
114
+ tools: this.tools.listAll()
115
+ });
116
+ }
117
+ };
118
+
119
+ Object.defineProperty(exports, "CreateChunkInputSchema", {
120
+ enumerable: true,
121
+ get: function () { return rag.CreateChunkInputSchema; }
122
+ });
123
+ Object.defineProperty(exports, "CreateDocumentInputSchema", {
124
+ enumerable: true,
125
+ get: function () { return rag.CreateDocumentInputSchema; }
126
+ });
127
+ Object.defineProperty(exports, "DocumentChunkSchema", {
128
+ enumerable: true,
129
+ get: function () { return rag.DocumentChunkSchema; }
130
+ });
131
+ Object.defineProperty(exports, "DocumentSchema", {
132
+ enumerable: true,
133
+ get: function () { return rag.DocumentSchema; }
134
+ });
135
+ Object.defineProperty(exports, "InMemoryVectorStore", {
136
+ enumerable: true,
137
+ get: function () { return rag.InMemoryVectorStore; }
138
+ });
139
+ Object.defineProperty(exports, "MockEmbeddingProvider", {
140
+ enumerable: true,
141
+ get: function () { return rag.MockEmbeddingProvider; }
142
+ });
143
+ Object.defineProperty(exports, "RagQuerySchema", {
144
+ enumerable: true,
145
+ get: function () { return rag.RagQuerySchema; }
146
+ });
147
+ Object.defineProperty(exports, "TextChunker", {
148
+ enumerable: true,
149
+ get: function () { return rag.TextChunker; }
150
+ });
151
+ Object.defineProperty(exports, "estimateTokenCount", {
152
+ enumerable: true,
153
+ get: function () { return rag.estimateTokenCount; }
154
+ });
155
+ exports.DEFAULT_CLIENT_TIMEOUT_MS = DEFAULT_CLIENT_TIMEOUT_MS;
156
+ exports.DEFAULT_GATEWAY_URL = DEFAULT_GATEWAY_URL;
157
+ exports.DevLabClient = DevLabClient;
158
+ exports.SDK_VERSION = SDK_VERSION;
159
+ Object.keys(agentCore).forEach(function (k) {
160
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
161
+ enumerable: true,
162
+ get: function () { return agentCore[k]; }
163
+ });
164
+ });
165
+ Object.keys(aiClient).forEach(function (k) {
166
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
167
+ enumerable: true,
168
+ get: function () { return aiClient[k]; }
169
+ });
170
+ });
171
+ Object.keys(billing).forEach(function (k) {
172
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
173
+ enumerable: true,
174
+ get: function () { return billing[k]; }
175
+ });
176
+ });
177
+ Object.keys(events).forEach(function (k) {
178
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
179
+ enumerable: true,
180
+ get: function () { return events[k]; }
181
+ });
182
+ });
183
+ Object.keys(semanticCache).forEach(function (k) {
184
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
185
+ enumerable: true,
186
+ get: function () { return semanticCache[k]; }
187
+ });
188
+ });
189
+ Object.keys(errors).forEach(function (k) {
190
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
191
+ enumerable: true,
192
+ get: function () { return errors[k]; }
193
+ });
194
+ });
195
+ Object.keys(resilience).forEach(function (k) {
196
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
197
+ enumerable: true,
198
+ get: function () { return resilience[k]; }
199
+ });
200
+ });
201
+ //# sourceMappingURL=index.cjs.map
202
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants/sdk.constants.ts","../src/client/devlab-client.ts"],"names":["loggerWithConfig","Logger","createDefaultProvider","MockEmbeddingProvider","TextChunker","InMemoryVectorStore","SemanticCache","ToolRegistry","DynamicPricingResolver","CostLedger","BudgetEnforcer","TokenCounter","InMemoryEventBus","compilePrompt"],"mappings":"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","file":"index.cjs","sourcesContent":["/**\n * @file packages/sdk/src/constants/sdk.constants.ts\n * @description Operational constants and default endpoints for the master DevLab client.\n * @module @yuva-devlab/sdk\n */\n\n/** Default client request timeout in milliseconds (30 seconds) */\nexport const DEFAULT_CLIENT_TIMEOUT_MS = 30_000;\n\n/** Default local gateway API base URL */\nexport const DEFAULT_GATEWAY_URL = \"http://localhost:3000\";\n\n/** Current SDK distribution version */\nexport const SDK_VERSION = \"0.1.0\";\n","/**\n * @file packages/sdk/src/client/devlab-client.ts\n * @description Master DevLab platform client unifying AI, RAG, swarms, billing, caching, and events.\n * @module @yuva-devlab/sdk\n */\n\nimport {\n ToolRegistry,\n compilePrompt,\n type UniversalTool,\n} from \"@yuva-devlab/agent-core\";\nimport {\n createDefaultProvider,\n type ILLMProvider,\n type LLMRequest,\n type LLMResponse,\n type LLMStreamChunk,\n} from \"@yuva-devlab/ai-client\";\nimport {\n BudgetEnforcer,\n CostLedger,\n DynamicPricingResolver,\n TokenCounter,\n} from \"@yuva-devlab/billing\";\nimport { InMemoryEventBus, type IEventBus } from \"@yuva-devlab/events\";\nimport { Logger, loggerWithConfig } from \"@yuva-devlab/logger\";\nimport {\n InMemoryVectorStore,\n MockEmbeddingProvider,\n TextChunker,\n type IEmbeddingProvider,\n type RagQuery,\n type RagSearchResult,\n} from \"@yuva-devlab/rag\";\nimport { SemanticCache } from \"@yuva-devlab/semantic-cache\";\nimport { DEFAULT_CLIENT_TIMEOUT_MS, DEFAULT_GATEWAY_URL } from \"../constants\";\nimport type { DevLabClientConfig } from \"../types\";\n\nconst logger = loggerWithConfig(new Logger(\"DevLabClient\"));\n\n/**\n * Master client providing unified access to the complete DevLab platform capabilities.\n *\n * @example\n * ```typescript\n * import { DevLabClient } from \"@yuva-devlab/sdk\";\n *\n * const client = new DevLabClient({ apiKey: \"dlk_...\" });\n * const response = await client.complete({\n * model: \"gemini-2.5-flash\",\n * messages: [{ role: \"user\", content: \"Hello!\" }],\n * });\n * ```\n */\nexport class DevLabClient {\n public readonly ai: ILLMProvider;\n public readonly embedder: IEmbeddingProvider;\n public readonly cache: SemanticCache;\n public readonly tools: ToolRegistry;\n public readonly vectorStore: InMemoryVectorStore;\n public readonly chunker: TextChunker;\n public readonly events: IEventBus;\n public readonly billing: {\n readonly counter: TokenCounter;\n readonly ledger: CostLedger;\n readonly enforcer: BudgetEnforcer;\n readonly pricing: DynamicPricingResolver;\n };\n\n public readonly gatewayUrl: string;\n public readonly tenantId?: string;\n public readonly timeoutMs: number;\n\n /**\n * Initializes the unified DevLab platform client.\n *\n * @param config - Platform client options\n */\n public constructor(config: DevLabClientConfig = {}) {\n this.gatewayUrl = config.gatewayUrl ?? DEFAULT_GATEWAY_URL;\n this.tenantId = config.tenantId;\n this.timeoutMs = config.timeoutMs ?? DEFAULT_CLIENT_TIMEOUT_MS;\n\n // 1. Initialize AI inference\n this.ai = config.aiProvider ?? createDefaultProvider();\n\n // 2. Initialize Embeddings & Vector RAG\n this.embedder = config.embeddingProvider ?? new MockEmbeddingProvider();\n this.chunker = new TextChunker();\n this.vectorStore = new InMemoryVectorStore(this.embedder);\n\n // 3. Initialize Semantic Caching\n this.cache = new SemanticCache(this.embedder);\n\n // 4. Initialize Agent Tool Registry\n this.tools = new ToolRegistry();\n\n // 5. Initialize Server-Driven Billing & Metering\n const pricing = new DynamicPricingResolver({\n loader: config.pricingLoader,\n });\n const ledger = new CostLedger();\n const enforcer = new BudgetEnforcer(ledger);\n const counter = new TokenCounter({ pricingResolver: pricing });\n this.billing = { counter, ledger, enforcer, pricing };\n\n // 6. Initialize Distributed Event Bus\n this.events = config.eventBus ?? new InMemoryEventBus();\n\n logger.debug(\"[constructor] DevLabClient initialized\", {\n gatewayUrl: this.gatewayUrl,\n tenantId: this.tenantId,\n });\n }\n\n /**\n * Completes an LLM prompt request.\n *\n * @param request - LLM completion request\n * @returns Model response\n */\n public async complete(request: LLMRequest): Promise<LLMResponse> {\n logger.debug(\"[complete] Executing AI completion via unified client\", {\n model: request.model,\n });\n return this.ai.complete(request);\n }\n\n /**\n * Streams token chunks incrementally.\n *\n * @param request - LLM completion request\n * @returns Async iterable yielding token deltas\n */\n public async *stream(request: LLMRequest): AsyncIterable<LLMStreamChunk> {\n yield* this.ai.stream(request);\n }\n\n /**\n * Executes a vector similarity search across ingested document chunks.\n *\n * @param query - Search parameters\n * @returns Scored document chunks\n */\n public async search(query: RagQuery): Promise<RagSearchResult> {\n logger.debug(\"[search] Executing RAG search via unified client\", {\n query: query.query,\n });\n return this.vectorStore.search(query);\n }\n\n /**\n * Executes a registered agent tool by name.\n *\n * @param toolName - Registered tool slug\n * @param input - Tool input arguments\n * @param ctx - Tool execution context\n * @returns Tool execution result\n */\n public async executeTool<TInput = unknown, TOutput = unknown>(\n toolName: string,\n input: TInput,\n ctx: { executionId: string; tenantId?: string },\n ): Promise<TOutput> {\n logger.debug(\"[executeTool] Executing registered tool\", { toolName });\n const tool = this.tools.getOrThrow(toolName) as UniversalTool<\n TInput,\n TOutput\n >;\n return tool.execute(input, {\n executionId: ctx.executionId,\n tenantId: ctx.tenantId ?? this.tenantId,\n });\n }\n\n /**\n * Helper to compile a system prompt with tool documentation.\n */\n public compilePrompt(\n template: string,\n variables: Record<string, unknown> = {},\n ): string {\n return compilePrompt({\n template,\n variables,\n tools: this.tools.listAll(),\n });\n }\n}\n"]}
@@ -0,0 +1,140 @@
1
+ import { ILLMProvider, LLMRequest, LLMResponse, LLMStreamChunk } from '@yuva-devlab/ai-client';
2
+ export * from '@yuva-devlab/ai-client';
3
+ import { PricingLoaderFn, TokenCounter, CostLedger, BudgetEnforcer, DynamicPricingResolver } from '@yuva-devlab/billing';
4
+ export * from '@yuva-devlab/billing';
5
+ import { IEventBus } from '@yuva-devlab/events';
6
+ export * from '@yuva-devlab/events';
7
+ import { IEmbeddingProvider, InMemoryVectorStore, TextChunker, RagQuery, RagSearchResult } from '@yuva-devlab/rag';
8
+ export { ChunkingOptions, CreateChunkInput, CreateChunkInputSchema, CreateDocumentInput, CreateDocumentInputSchema, Document, DocumentChunk, DocumentChunkSchema, DocumentSchema, ITextChunker, InMemoryVectorStore, MockEmbeddingProvider, RagQuery, RagQuerySchema, RagSearchResult, ScoredDocumentChunk, TextChunker, estimateTokenCount } from '@yuva-devlab/rag';
9
+ import { ToolRegistry } from '@yuva-devlab/agent-core';
10
+ export * from '@yuva-devlab/agent-core';
11
+ import { SemanticCache } from '@yuva-devlab/semantic-cache';
12
+ export * from '@yuva-devlab/semantic-cache';
13
+ export * from '@yuva-devlab/errors';
14
+ export * from '@yuva-devlab/resilience';
15
+
16
+ /**
17
+ * @file packages/sdk/src/constants/sdk.constants.ts
18
+ * @description Operational constants and default endpoints for the master DevLab client.
19
+ * @module @yuva-devlab/sdk
20
+ */
21
+ /** Default client request timeout in milliseconds (30 seconds) */
22
+ declare const DEFAULT_CLIENT_TIMEOUT_MS = 30000;
23
+ /** Default local gateway API base URL */
24
+ declare const DEFAULT_GATEWAY_URL = "http://localhost:3000";
25
+ /** Current SDK distribution version */
26
+ declare const SDK_VERSION = "0.1.0";
27
+
28
+ /**
29
+ * @file packages/sdk/src/types/client.types.ts
30
+ * @description Configuration and options for the unified DevLabClient platform SDK.
31
+ * @module @yuva-devlab/sdk
32
+ */
33
+
34
+ /**
35
+ * Configuration options for initializing the master DevLabClient.
36
+ */
37
+ interface DevLabClientConfig {
38
+ /** Optional machine API key for authenticating with the DevLab Gateway */
39
+ readonly apiKey?: string;
40
+ /** Optional gateway base URL (defaults to DEFAULT_GATEWAY_URL) */
41
+ readonly gatewayUrl?: string;
42
+ /** Unique platform application slug (e.g. "finai", "orchestrai") */
43
+ readonly appId?: string;
44
+ /** Tenant isolation partition ID */
45
+ readonly tenantId?: string;
46
+ /** Custom LLM provider adapter override */
47
+ readonly aiProvider?: ILLMProvider;
48
+ /** Custom vector embedding provider override */
49
+ readonly embeddingProvider?: IEmbeddingProvider;
50
+ /** Custom domain event bus instance */
51
+ readonly eventBus?: IEventBus;
52
+ /** Remote pricing loader callback */
53
+ readonly pricingLoader?: PricingLoaderFn;
54
+ /** Global request timeout in milliseconds */
55
+ readonly timeoutMs?: number;
56
+ }
57
+
58
+ /**
59
+ * @file packages/sdk/src/client/devlab-client.ts
60
+ * @description Master DevLab platform client unifying AI, RAG, swarms, billing, caching, and events.
61
+ * @module @yuva-devlab/sdk
62
+ */
63
+
64
+ /**
65
+ * Master client providing unified access to the complete DevLab platform capabilities.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * import { DevLabClient } from "@yuva-devlab/sdk";
70
+ *
71
+ * const client = new DevLabClient({ apiKey: "dlk_..." });
72
+ * const response = await client.complete({
73
+ * model: "gemini-2.5-flash",
74
+ * messages: [{ role: "user", content: "Hello!" }],
75
+ * });
76
+ * ```
77
+ */
78
+ declare class DevLabClient {
79
+ readonly ai: ILLMProvider;
80
+ readonly embedder: IEmbeddingProvider;
81
+ readonly cache: SemanticCache;
82
+ readonly tools: ToolRegistry;
83
+ readonly vectorStore: InMemoryVectorStore;
84
+ readonly chunker: TextChunker;
85
+ readonly events: IEventBus;
86
+ readonly billing: {
87
+ readonly counter: TokenCounter;
88
+ readonly ledger: CostLedger;
89
+ readonly enforcer: BudgetEnforcer;
90
+ readonly pricing: DynamicPricingResolver;
91
+ };
92
+ readonly gatewayUrl: string;
93
+ readonly tenantId?: string;
94
+ readonly timeoutMs: number;
95
+ /**
96
+ * Initializes the unified DevLab platform client.
97
+ *
98
+ * @param config - Platform client options
99
+ */
100
+ constructor(config?: DevLabClientConfig);
101
+ /**
102
+ * Completes an LLM prompt request.
103
+ *
104
+ * @param request - LLM completion request
105
+ * @returns Model response
106
+ */
107
+ complete(request: LLMRequest): Promise<LLMResponse>;
108
+ /**
109
+ * Streams token chunks incrementally.
110
+ *
111
+ * @param request - LLM completion request
112
+ * @returns Async iterable yielding token deltas
113
+ */
114
+ stream(request: LLMRequest): AsyncIterable<LLMStreamChunk>;
115
+ /**
116
+ * Executes a vector similarity search across ingested document chunks.
117
+ *
118
+ * @param query - Search parameters
119
+ * @returns Scored document chunks
120
+ */
121
+ search(query: RagQuery): Promise<RagSearchResult>;
122
+ /**
123
+ * Executes a registered agent tool by name.
124
+ *
125
+ * @param toolName - Registered tool slug
126
+ * @param input - Tool input arguments
127
+ * @param ctx - Tool execution context
128
+ * @returns Tool execution result
129
+ */
130
+ executeTool<TInput = unknown, TOutput = unknown>(toolName: string, input: TInput, ctx: {
131
+ executionId: string;
132
+ tenantId?: string;
133
+ }): Promise<TOutput>;
134
+ /**
135
+ * Helper to compile a system prompt with tool documentation.
136
+ */
137
+ compilePrompt(template: string, variables?: Record<string, unknown>): string;
138
+ }
139
+
140
+ export { DEFAULT_CLIENT_TIMEOUT_MS, DEFAULT_GATEWAY_URL, DevLabClient, type DevLabClientConfig, SDK_VERSION };
@@ -0,0 +1,140 @@
1
+ import { ILLMProvider, LLMRequest, LLMResponse, LLMStreamChunk } from '@yuva-devlab/ai-client';
2
+ export * from '@yuva-devlab/ai-client';
3
+ import { PricingLoaderFn, TokenCounter, CostLedger, BudgetEnforcer, DynamicPricingResolver } from '@yuva-devlab/billing';
4
+ export * from '@yuva-devlab/billing';
5
+ import { IEventBus } from '@yuva-devlab/events';
6
+ export * from '@yuva-devlab/events';
7
+ import { IEmbeddingProvider, InMemoryVectorStore, TextChunker, RagQuery, RagSearchResult } from '@yuva-devlab/rag';
8
+ export { ChunkingOptions, CreateChunkInput, CreateChunkInputSchema, CreateDocumentInput, CreateDocumentInputSchema, Document, DocumentChunk, DocumentChunkSchema, DocumentSchema, ITextChunker, InMemoryVectorStore, MockEmbeddingProvider, RagQuery, RagQuerySchema, RagSearchResult, ScoredDocumentChunk, TextChunker, estimateTokenCount } from '@yuva-devlab/rag';
9
+ import { ToolRegistry } from '@yuva-devlab/agent-core';
10
+ export * from '@yuva-devlab/agent-core';
11
+ import { SemanticCache } from '@yuva-devlab/semantic-cache';
12
+ export * from '@yuva-devlab/semantic-cache';
13
+ export * from '@yuva-devlab/errors';
14
+ export * from '@yuva-devlab/resilience';
15
+
16
+ /**
17
+ * @file packages/sdk/src/constants/sdk.constants.ts
18
+ * @description Operational constants and default endpoints for the master DevLab client.
19
+ * @module @yuva-devlab/sdk
20
+ */
21
+ /** Default client request timeout in milliseconds (30 seconds) */
22
+ declare const DEFAULT_CLIENT_TIMEOUT_MS = 30000;
23
+ /** Default local gateway API base URL */
24
+ declare const DEFAULT_GATEWAY_URL = "http://localhost:3000";
25
+ /** Current SDK distribution version */
26
+ declare const SDK_VERSION = "0.1.0";
27
+
28
+ /**
29
+ * @file packages/sdk/src/types/client.types.ts
30
+ * @description Configuration and options for the unified DevLabClient platform SDK.
31
+ * @module @yuva-devlab/sdk
32
+ */
33
+
34
+ /**
35
+ * Configuration options for initializing the master DevLabClient.
36
+ */
37
+ interface DevLabClientConfig {
38
+ /** Optional machine API key for authenticating with the DevLab Gateway */
39
+ readonly apiKey?: string;
40
+ /** Optional gateway base URL (defaults to DEFAULT_GATEWAY_URL) */
41
+ readonly gatewayUrl?: string;
42
+ /** Unique platform application slug (e.g. "finai", "orchestrai") */
43
+ readonly appId?: string;
44
+ /** Tenant isolation partition ID */
45
+ readonly tenantId?: string;
46
+ /** Custom LLM provider adapter override */
47
+ readonly aiProvider?: ILLMProvider;
48
+ /** Custom vector embedding provider override */
49
+ readonly embeddingProvider?: IEmbeddingProvider;
50
+ /** Custom domain event bus instance */
51
+ readonly eventBus?: IEventBus;
52
+ /** Remote pricing loader callback */
53
+ readonly pricingLoader?: PricingLoaderFn;
54
+ /** Global request timeout in milliseconds */
55
+ readonly timeoutMs?: number;
56
+ }
57
+
58
+ /**
59
+ * @file packages/sdk/src/client/devlab-client.ts
60
+ * @description Master DevLab platform client unifying AI, RAG, swarms, billing, caching, and events.
61
+ * @module @yuva-devlab/sdk
62
+ */
63
+
64
+ /**
65
+ * Master client providing unified access to the complete DevLab platform capabilities.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * import { DevLabClient } from "@yuva-devlab/sdk";
70
+ *
71
+ * const client = new DevLabClient({ apiKey: "dlk_..." });
72
+ * const response = await client.complete({
73
+ * model: "gemini-2.5-flash",
74
+ * messages: [{ role: "user", content: "Hello!" }],
75
+ * });
76
+ * ```
77
+ */
78
+ declare class DevLabClient {
79
+ readonly ai: ILLMProvider;
80
+ readonly embedder: IEmbeddingProvider;
81
+ readonly cache: SemanticCache;
82
+ readonly tools: ToolRegistry;
83
+ readonly vectorStore: InMemoryVectorStore;
84
+ readonly chunker: TextChunker;
85
+ readonly events: IEventBus;
86
+ readonly billing: {
87
+ readonly counter: TokenCounter;
88
+ readonly ledger: CostLedger;
89
+ readonly enforcer: BudgetEnforcer;
90
+ readonly pricing: DynamicPricingResolver;
91
+ };
92
+ readonly gatewayUrl: string;
93
+ readonly tenantId?: string;
94
+ readonly timeoutMs: number;
95
+ /**
96
+ * Initializes the unified DevLab platform client.
97
+ *
98
+ * @param config - Platform client options
99
+ */
100
+ constructor(config?: DevLabClientConfig);
101
+ /**
102
+ * Completes an LLM prompt request.
103
+ *
104
+ * @param request - LLM completion request
105
+ * @returns Model response
106
+ */
107
+ complete(request: LLMRequest): Promise<LLMResponse>;
108
+ /**
109
+ * Streams token chunks incrementally.
110
+ *
111
+ * @param request - LLM completion request
112
+ * @returns Async iterable yielding token deltas
113
+ */
114
+ stream(request: LLMRequest): AsyncIterable<LLMStreamChunk>;
115
+ /**
116
+ * Executes a vector similarity search across ingested document chunks.
117
+ *
118
+ * @param query - Search parameters
119
+ * @returns Scored document chunks
120
+ */
121
+ search(query: RagQuery): Promise<RagSearchResult>;
122
+ /**
123
+ * Executes a registered agent tool by name.
124
+ *
125
+ * @param toolName - Registered tool slug
126
+ * @param input - Tool input arguments
127
+ * @param ctx - Tool execution context
128
+ * @returns Tool execution result
129
+ */
130
+ executeTool<TInput = unknown, TOutput = unknown>(toolName: string, input: TInput, ctx: {
131
+ executionId: string;
132
+ tenantId?: string;
133
+ }): Promise<TOutput>;
134
+ /**
135
+ * Helper to compile a system prompt with tool documentation.
136
+ */
137
+ compilePrompt(template: string, variables?: Record<string, unknown>): string;
138
+ }
139
+
140
+ export { DEFAULT_CLIENT_TIMEOUT_MS, DEFAULT_GATEWAY_URL, DevLabClient, type DevLabClientConfig, SDK_VERSION };
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ import { ToolRegistry, compilePrompt } from '@yuva-devlab/agent-core';
2
+ export * from '@yuva-devlab/agent-core';
3
+ import { createDefaultProvider } from '@yuva-devlab/ai-client';
4
+ export * from '@yuva-devlab/ai-client';
5
+ import { DynamicPricingResolver, CostLedger, BudgetEnforcer, TokenCounter } from '@yuva-devlab/billing';
6
+ export * from '@yuva-devlab/billing';
7
+ import { InMemoryEventBus } from '@yuva-devlab/events';
8
+ export * from '@yuva-devlab/events';
9
+ import { loggerWithConfig, Logger } from '@yuva-devlab/logger';
10
+ import { MockEmbeddingProvider, TextChunker, InMemoryVectorStore } from '@yuva-devlab/rag';
11
+ export { CreateChunkInputSchema, CreateDocumentInputSchema, DocumentChunkSchema, DocumentSchema, InMemoryVectorStore, MockEmbeddingProvider, RagQuerySchema, TextChunker, estimateTokenCount } from '@yuva-devlab/rag';
12
+ import { SemanticCache } from '@yuva-devlab/semantic-cache';
13
+ export * from '@yuva-devlab/semantic-cache';
14
+ export * from '@yuva-devlab/errors';
15
+ export * from '@yuva-devlab/resilience';
16
+
17
+ // src/constants/sdk.constants.ts
18
+ var DEFAULT_CLIENT_TIMEOUT_MS = 3e4;
19
+ var DEFAULT_GATEWAY_URL = "http://localhost:3000";
20
+ var SDK_VERSION = "0.1.0";
21
+ var logger = loggerWithConfig(new Logger("DevLabClient"));
22
+ var DevLabClient = class {
23
+ ai;
24
+ embedder;
25
+ cache;
26
+ tools;
27
+ vectorStore;
28
+ chunker;
29
+ events;
30
+ billing;
31
+ gatewayUrl;
32
+ tenantId;
33
+ timeoutMs;
34
+ /**
35
+ * Initializes the unified DevLab platform client.
36
+ *
37
+ * @param config - Platform client options
38
+ */
39
+ constructor(config = {}) {
40
+ this.gatewayUrl = config.gatewayUrl ?? DEFAULT_GATEWAY_URL;
41
+ this.tenantId = config.tenantId;
42
+ this.timeoutMs = config.timeoutMs ?? DEFAULT_CLIENT_TIMEOUT_MS;
43
+ this.ai = config.aiProvider ?? createDefaultProvider();
44
+ this.embedder = config.embeddingProvider ?? new MockEmbeddingProvider();
45
+ this.chunker = new TextChunker();
46
+ this.vectorStore = new InMemoryVectorStore(this.embedder);
47
+ this.cache = new SemanticCache(this.embedder);
48
+ this.tools = new ToolRegistry();
49
+ const pricing = new DynamicPricingResolver({
50
+ loader: config.pricingLoader
51
+ });
52
+ const ledger = new CostLedger();
53
+ const enforcer = new BudgetEnforcer(ledger);
54
+ const counter = new TokenCounter({ pricingResolver: pricing });
55
+ this.billing = { counter, ledger, enforcer, pricing };
56
+ this.events = config.eventBus ?? new InMemoryEventBus();
57
+ logger.debug("[constructor] DevLabClient initialized", {
58
+ gatewayUrl: this.gatewayUrl,
59
+ tenantId: this.tenantId
60
+ });
61
+ }
62
+ /**
63
+ * Completes an LLM prompt request.
64
+ *
65
+ * @param request - LLM completion request
66
+ * @returns Model response
67
+ */
68
+ async complete(request) {
69
+ logger.debug("[complete] Executing AI completion via unified client", {
70
+ model: request.model
71
+ });
72
+ return this.ai.complete(request);
73
+ }
74
+ /**
75
+ * Streams token chunks incrementally.
76
+ *
77
+ * @param request - LLM completion request
78
+ * @returns Async iterable yielding token deltas
79
+ */
80
+ async *stream(request) {
81
+ yield* this.ai.stream(request);
82
+ }
83
+ /**
84
+ * Executes a vector similarity search across ingested document chunks.
85
+ *
86
+ * @param query - Search parameters
87
+ * @returns Scored document chunks
88
+ */
89
+ async search(query) {
90
+ logger.debug("[search] Executing RAG search via unified client", {
91
+ query: query.query
92
+ });
93
+ return this.vectorStore.search(query);
94
+ }
95
+ /**
96
+ * Executes a registered agent tool by name.
97
+ *
98
+ * @param toolName - Registered tool slug
99
+ * @param input - Tool input arguments
100
+ * @param ctx - Tool execution context
101
+ * @returns Tool execution result
102
+ */
103
+ async executeTool(toolName, input, ctx) {
104
+ logger.debug("[executeTool] Executing registered tool", { toolName });
105
+ const tool = this.tools.getOrThrow(toolName);
106
+ return tool.execute(input, {
107
+ executionId: ctx.executionId,
108
+ tenantId: ctx.tenantId ?? this.tenantId
109
+ });
110
+ }
111
+ /**
112
+ * Helper to compile a system prompt with tool documentation.
113
+ */
114
+ compilePrompt(template, variables = {}) {
115
+ return compilePrompt({
116
+ template,
117
+ variables,
118
+ tools: this.tools.listAll()
119
+ });
120
+ }
121
+ };
122
+
123
+ export { DEFAULT_CLIENT_TIMEOUT_MS, DEFAULT_GATEWAY_URL, DevLabClient, SDK_VERSION };
124
+ //# sourceMappingURL=index.js.map
125
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants/sdk.constants.ts","../src/client/devlab-client.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["/**\n * @file packages/sdk/src/constants/sdk.constants.ts\n * @description Operational constants and default endpoints for the master DevLab client.\n * @module @yuva-devlab/sdk\n */\n\n/** Default client request timeout in milliseconds (30 seconds) */\nexport const DEFAULT_CLIENT_TIMEOUT_MS = 30_000;\n\n/** Default local gateway API base URL */\nexport const DEFAULT_GATEWAY_URL = \"http://localhost:3000\";\n\n/** Current SDK distribution version */\nexport const SDK_VERSION = \"0.1.0\";\n","/**\n * @file packages/sdk/src/client/devlab-client.ts\n * @description Master DevLab platform client unifying AI, RAG, swarms, billing, caching, and events.\n * @module @yuva-devlab/sdk\n */\n\nimport {\n ToolRegistry,\n compilePrompt,\n type UniversalTool,\n} from \"@yuva-devlab/agent-core\";\nimport {\n createDefaultProvider,\n type ILLMProvider,\n type LLMRequest,\n type LLMResponse,\n type LLMStreamChunk,\n} from \"@yuva-devlab/ai-client\";\nimport {\n BudgetEnforcer,\n CostLedger,\n DynamicPricingResolver,\n TokenCounter,\n} from \"@yuva-devlab/billing\";\nimport { InMemoryEventBus, type IEventBus } from \"@yuva-devlab/events\";\nimport { Logger, loggerWithConfig } from \"@yuva-devlab/logger\";\nimport {\n InMemoryVectorStore,\n MockEmbeddingProvider,\n TextChunker,\n type IEmbeddingProvider,\n type RagQuery,\n type RagSearchResult,\n} from \"@yuva-devlab/rag\";\nimport { SemanticCache } from \"@yuva-devlab/semantic-cache\";\nimport { DEFAULT_CLIENT_TIMEOUT_MS, DEFAULT_GATEWAY_URL } from \"../constants\";\nimport type { DevLabClientConfig } from \"../types\";\n\nconst logger = loggerWithConfig(new Logger(\"DevLabClient\"));\n\n/**\n * Master client providing unified access to the complete DevLab platform capabilities.\n *\n * @example\n * ```typescript\n * import { DevLabClient } from \"@yuva-devlab/sdk\";\n *\n * const client = new DevLabClient({ apiKey: \"dlk_...\" });\n * const response = await client.complete({\n * model: \"gemini-2.5-flash\",\n * messages: [{ role: \"user\", content: \"Hello!\" }],\n * });\n * ```\n */\nexport class DevLabClient {\n public readonly ai: ILLMProvider;\n public readonly embedder: IEmbeddingProvider;\n public readonly cache: SemanticCache;\n public readonly tools: ToolRegistry;\n public readonly vectorStore: InMemoryVectorStore;\n public readonly chunker: TextChunker;\n public readonly events: IEventBus;\n public readonly billing: {\n readonly counter: TokenCounter;\n readonly ledger: CostLedger;\n readonly enforcer: BudgetEnforcer;\n readonly pricing: DynamicPricingResolver;\n };\n\n public readonly gatewayUrl: string;\n public readonly tenantId?: string;\n public readonly timeoutMs: number;\n\n /**\n * Initializes the unified DevLab platform client.\n *\n * @param config - Platform client options\n */\n public constructor(config: DevLabClientConfig = {}) {\n this.gatewayUrl = config.gatewayUrl ?? DEFAULT_GATEWAY_URL;\n this.tenantId = config.tenantId;\n this.timeoutMs = config.timeoutMs ?? DEFAULT_CLIENT_TIMEOUT_MS;\n\n // 1. Initialize AI inference\n this.ai = config.aiProvider ?? createDefaultProvider();\n\n // 2. Initialize Embeddings & Vector RAG\n this.embedder = config.embeddingProvider ?? new MockEmbeddingProvider();\n this.chunker = new TextChunker();\n this.vectorStore = new InMemoryVectorStore(this.embedder);\n\n // 3. Initialize Semantic Caching\n this.cache = new SemanticCache(this.embedder);\n\n // 4. Initialize Agent Tool Registry\n this.tools = new ToolRegistry();\n\n // 5. Initialize Server-Driven Billing & Metering\n const pricing = new DynamicPricingResolver({\n loader: config.pricingLoader,\n });\n const ledger = new CostLedger();\n const enforcer = new BudgetEnforcer(ledger);\n const counter = new TokenCounter({ pricingResolver: pricing });\n this.billing = { counter, ledger, enforcer, pricing };\n\n // 6. Initialize Distributed Event Bus\n this.events = config.eventBus ?? new InMemoryEventBus();\n\n logger.debug(\"[constructor] DevLabClient initialized\", {\n gatewayUrl: this.gatewayUrl,\n tenantId: this.tenantId,\n });\n }\n\n /**\n * Completes an LLM prompt request.\n *\n * @param request - LLM completion request\n * @returns Model response\n */\n public async complete(request: LLMRequest): Promise<LLMResponse> {\n logger.debug(\"[complete] Executing AI completion via unified client\", {\n model: request.model,\n });\n return this.ai.complete(request);\n }\n\n /**\n * Streams token chunks incrementally.\n *\n * @param request - LLM completion request\n * @returns Async iterable yielding token deltas\n */\n public async *stream(request: LLMRequest): AsyncIterable<LLMStreamChunk> {\n yield* this.ai.stream(request);\n }\n\n /**\n * Executes a vector similarity search across ingested document chunks.\n *\n * @param query - Search parameters\n * @returns Scored document chunks\n */\n public async search(query: RagQuery): Promise<RagSearchResult> {\n logger.debug(\"[search] Executing RAG search via unified client\", {\n query: query.query,\n });\n return this.vectorStore.search(query);\n }\n\n /**\n * Executes a registered agent tool by name.\n *\n * @param toolName - Registered tool slug\n * @param input - Tool input arguments\n * @param ctx - Tool execution context\n * @returns Tool execution result\n */\n public async executeTool<TInput = unknown, TOutput = unknown>(\n toolName: string,\n input: TInput,\n ctx: { executionId: string; tenantId?: string },\n ): Promise<TOutput> {\n logger.debug(\"[executeTool] Executing registered tool\", { toolName });\n const tool = this.tools.getOrThrow(toolName) as UniversalTool<\n TInput,\n TOutput\n >;\n return tool.execute(input, {\n executionId: ctx.executionId,\n tenantId: ctx.tenantId ?? this.tenantId,\n });\n }\n\n /**\n * Helper to compile a system prompt with tool documentation.\n */\n public compilePrompt(\n template: string,\n variables: Record<string, unknown> = {},\n ): string {\n return compilePrompt({\n template,\n variables,\n tools: this.tools.listAll(),\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@yuva-devlab/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Unified Master DevLab Platform Client combining AI inference, RAG, swarms, billing, caching, and events",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": {
12
+ "import": "./dist/index.d.ts",
13
+ "require": "./dist/index.d.cts"
14
+ },
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs"
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "zod": "^3.25.76",
29
+ "@yuva-devlab/agent-core": "0.2.0",
30
+ "@yuva-devlab/ai-client": "0.2.0",
31
+ "@yuva-devlab/auth-server": "0.2.0",
32
+ "@yuva-devlab/billing": "0.2.0",
33
+ "@yuva-devlab/errors": "0.2.0",
34
+ "@yuva-devlab/events": "0.2.0",
35
+ "@yuva-devlab/logger": "1.2.0",
36
+ "@yuva-devlab/rag": "0.2.0",
37
+ "@yuva-devlab/resilience": "0.2.0",
38
+ "@yuva-devlab/semantic-cache": "0.2.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^24.10.1",
42
+ "eslint": "^9.39.1",
43
+ "prettier": "^3.9.8",
44
+ "tsup": "^8.5.1",
45
+ "typescript": "^6.0.3",
46
+ "@yuva-devlab/eslint-config": "0.1.1",
47
+ "@yuva-devlab/prettier-config": "0.1.1",
48
+ "@yuva-devlab/typescript-config": "0.1.1"
49
+ },
50
+ "scripts": {
51
+ "build": "tsup",
52
+ "dev": "tsup --watch",
53
+ "lint": "eslint src",
54
+ "lint:fix": "eslint src --fix",
55
+ "format": "prettier --write .",
56
+ "format:check": "prettier --check .",
57
+ "typecheck": "tsc --noEmit",
58
+ "clean": "rm -rf dist node_modules .turbo"
59
+ }
6
60
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.