@vibesdotdev/runtime-client 0.0.1

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 (63) hide show
  1. package/README.md +97 -0
  2. package/SPEC.md +44 -0
  3. package/dist/base.d.ts +49 -0
  4. package/dist/base.d.ts.map +1 -0
  5. package/dist/base.js +86 -0
  6. package/dist/base.js.map +1 -0
  7. package/dist/contract.d.ts +23 -0
  8. package/dist/contract.d.ts.map +1 -0
  9. package/dist/contract.js +2 -0
  10. package/dist/contract.js.map +1 -0
  11. package/dist/docs/runtime-client.api.docs.descriptor.d.ts +8 -0
  12. package/dist/docs/runtime-client.api.docs.descriptor.d.ts.map +1 -0
  13. package/dist/docs/runtime-client.api.docs.descriptor.js +344 -0
  14. package/dist/docs/runtime-client.api.docs.descriptor.js.map +1 -0
  15. package/dist/docs/runtime-client.helpers.docs.descriptor.d.ts +8 -0
  16. package/dist/docs/runtime-client.helpers.docs.descriptor.d.ts.map +1 -0
  17. package/dist/docs/runtime-client.helpers.docs.descriptor.js +352 -0
  18. package/dist/docs/runtime-client.helpers.docs.descriptor.js.map +1 -0
  19. package/dist/docs/runtime-client.surface.docs.descriptor.d.ts +8 -0
  20. package/dist/docs/runtime-client.surface.docs.descriptor.d.ts.map +1 -0
  21. package/dist/docs/runtime-client.surface.docs.descriptor.js +464 -0
  22. package/dist/docs/runtime-client.surface.docs.descriptor.js.map +1 -0
  23. package/dist/docs/types.d.ts +19 -0
  24. package/dist/docs/types.d.ts.map +1 -0
  25. package/dist/docs/types.js +2 -0
  26. package/dist/docs/types.js.map +1 -0
  27. package/dist/helper.d.ts +14 -0
  28. package/dist/helper.d.ts.map +1 -0
  29. package/dist/helper.js +27 -0
  30. package/dist/helper.js.map +1 -0
  31. package/dist/index.d.ts +8 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +8 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/kind.d.ts +10 -0
  36. package/dist/kind.d.ts.map +1 -0
  37. package/dist/kind.js +12 -0
  38. package/dist/kind.js.map +1 -0
  39. package/dist/plugin.d.ts +10 -0
  40. package/dist/plugin.d.ts.map +1 -0
  41. package/dist/plugin.js +17 -0
  42. package/dist/plugin.js.map +1 -0
  43. package/dist/runtime-client.plugin.d.ts +13 -0
  44. package/dist/runtime-client.plugin.d.ts.map +1 -0
  45. package/dist/runtime-client.plugin.js +27 -0
  46. package/dist/runtime-client.plugin.js.map +1 -0
  47. package/dist/schema.d.ts +32 -0
  48. package/dist/schema.d.ts.map +1 -0
  49. package/dist/schema.js +8 -0
  50. package/dist/schema.js.map +1 -0
  51. package/package.json +61 -0
  52. package/src/base.ts +100 -0
  53. package/src/contract.ts +23 -0
  54. package/src/docs/runtime-client.api.docs.descriptor.ts +346 -0
  55. package/src/docs/runtime-client.helpers.docs.descriptor.ts +354 -0
  56. package/src/docs/runtime-client.surface.docs.descriptor.ts +466 -0
  57. package/src/docs/types.ts +18 -0
  58. package/src/helper.ts +32 -0
  59. package/src/index.ts +11 -0
  60. package/src/kind.ts +14 -0
  61. package/src/plugin.ts +19 -0
  62. package/src/runtime-client.plugin.ts +32 -0
  63. package/src/schema.ts +27 -0
@@ -0,0 +1,8 @@
1
+ import type { DocsTopicDescriptor } from './types.ts';
2
+ /**
3
+ * Descriptor for runtime-client.helpers
4
+ * getVibesClient() helper functions, surface detection
5
+ */
6
+ declare const descriptor: DocsTopicDescriptor;
7
+ export default descriptor;
8
+ //# sourceMappingURL=runtime-client.helpers.docs.descriptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-client.helpers.docs.descriptor.d.ts","sourceRoot":"","sources":["../../src/docs/runtime-client.helpers.docs.descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;GAGG;AACH,QAAA,MAAM,UAAU,EAAE,mBAyVjB,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,352 @@
1
+ /**
2
+ * Descriptor for runtime-client.helpers
3
+ * getVibesClient() helper functions, surface detection
4
+ */
5
+ const descriptor = {
6
+ kind: 'docs/topic',
7
+ id: 'runtime-client.helpers',
8
+ title: 'Runtime Client Helpers',
9
+ summary: 'getVibesClient() helper functions for resolving module clients by id',
10
+ body: {
11
+ type: 'markdown',
12
+ sourceType: 'raw',
13
+ source: `---
14
+ title: Runtime Client Helpers
15
+ summary: getVibesClient() helper functions for resolving module clients by id
16
+ tags: [runtime-client, helpers, getVibesClient, resolution, singleton]
17
+ parent: runtime-client
18
+ order: 2
19
+ surfaces: [cli, web, in-app]
20
+ hardware: [consumer, cloud]
21
+ ---
22
+
23
+ # Runtime Client Helpers
24
+
25
+ The \`@vibesdotdev/runtime-client\` package exports helper functions for resolving module-level clients without manual \`runtime.query()\` chains. These helpers abstract runtime acquisition, kind registration, and error handling.
26
+
27
+ ## getVibesClient<T>()
28
+
29
+ Primary helper for resolving a client by id:
30
+
31
+ \`\`\`ts
32
+ import { getVibesClient } from '@vibesdotdev/runtime-client';
33
+ import type { AIClient } from '@vibesdotdev/ai/client';
34
+
35
+ const ai = await getVibesClient<AIClient>('ai');
36
+ const response = await ai.generate({ prompt: 'Hello' });
37
+ \`\`\`
38
+
39
+ ### How it works
40
+
41
+ \`\`\`ts
42
+ // Simplified implementation
43
+ export async function getVibesClient<T extends RuntimeClient>(
44
+ id: string
45
+ ): Promise<T> {
46
+ const runtime = getVibesRuntime();
47
+
48
+ // Auto-register runtime/client kind if not present
49
+ if (!runtime.hasKind('runtime/client')) {
50
+ await runtime.registerPlugin(runtimeClientPlugin);
51
+ }
52
+
53
+ // Resolve via runtime.query()
54
+ const client = await runtime
55
+ .query('runtime/client')
56
+ .withId(id)
57
+ .resolve();
58
+
59
+ if (!client) {
60
+ throw new Error(
61
+ \`No runtime client registered with id "\${id}". \${
62
+ 'Compose the owning module\\'s plugin (e.g. aiPlugin for id="ai") ' +
63
+ 'before use, and ensure runtimeClientPlugin is registered.'
64
+ }\`
65
+ );
66
+ }
67
+
68
+ return client as T;
69
+ }
70
+ \`\`\`
71
+
72
+ ### Auto-registration semantics
73
+
74
+ \`getVibesClient()\` automatically registers the \`runtime/client\` kind if it hasn't been registered yet. This means:
75
+
76
+ 1. **No manual bootstrap required** — Call \`getVibesClient()\` directly
77
+ 2. **Kind registration is idempotent** — Safe to call multiple times
78
+ 3. **Module plugins still needed** — The module owning the client (e.g., \`aiPlugin\`) must still be registered to provide the implementation
79
+
80
+ \`\`\`ts
81
+ // ✅ Works — runtime/client kind auto-registered
82
+ import { getVibesClient } from '@vibesdotdev/runtime-client';
83
+ import { aiPlugin } from '@vibesdotdev/ai';
84
+
85
+ const runtime = getVibesRuntime();
86
+ await runtime.registerPlugin(aiPlugin); // Provides AIClient implementation
87
+
88
+ const ai = await getVibesClient('ai'); // ✅ Resolves AIClient
89
+ \`\`\`
90
+
91
+ ### Type safety
92
+
93
+ Use TypeScript generics for type-safe client access:
94
+
95
+ \`\`\`ts
96
+ import { getVibesClient } from '@vibesdotdev/runtime-client';
97
+ import type { ToolsClient } from '@vibesdotdev/tools/client';
98
+ import type { KnowledgeClient } from '@vibesdotdev/knowledge/client';
99
+
100
+ // Type-safe resolution
101
+ const tools = await getVibesClient<ToolsClient>('tools');
102
+ const knowledge = await getVibesClient<KnowledgeClient>('knowledge');
103
+
104
+ // IntelliSense works:
105
+ await tools.listTools(); // ✅ Typed
106
+ await knowledge.search('...'); // ✅ Typed
107
+ \`\`\`
108
+
109
+ ### Error handling
110
+
111
+ \`getVibesClient()\` throws if the client is not registered:
112
+
113
+ \`\`\`ts
114
+ try {
115
+ const ai = await getVibesClient('ai');
116
+ } catch (error) {
117
+ // Error: No runtime client registered with id "ai".
118
+ // Compose the owning module's plugin (e.g. aiPlugin for id="ai")
119
+ // before use, and ensure runtimeClientPlugin is registered.
120
+ }
121
+ \`\`\`
122
+
123
+ **Common causes:**
124
+ 1. Module plugin not registered (e.g., \`aiPlugin\`)
125
+ 2. Wrong client id (use \`'ai'\`, not \`'ai-client'\`)
126
+ 3. Runtime not bootstrapped (call \`getVibesRuntime()\` first)
127
+
128
+ ## Module-Specific Helper Wrappers
129
+
130
+ Many packages export their own typed helper that wraps \`getVibesClient()\`:
131
+
132
+ ### Example: Tools
133
+
134
+ \`\`\`ts
135
+ // packages/tools/src/client/helper.ts
136
+ import { getVibesClient } from '@vibesdotdev/runtime-client';
137
+ import type { ToolsClient } from './runtime-client';
138
+
139
+ export function getVibesToolsClient(): Promise<ToolsClient> {
140
+ return getVibesClient<ToolsClient>('tools');
141
+ }
142
+
143
+ // Usage
144
+ import { getVibesToolsClient } from '@vibesdotdev/tools/client';
145
+
146
+ const tools = await getVibesToolsClient();
147
+ const toolList = await tools.listTools();
148
+ \`\`\`
149
+
150
+ ### Example: AI
151
+
152
+ \`\`\`ts
153
+ // packages/ai/src/client/helper.ts
154
+ import { getVibesClient } from '@vibesdotdev/runtime-client';
155
+ import type { AIClient } from './ai-client';
156
+
157
+ export function getVibesAIClient(): Promise<AIClient> {
158
+ return getVibesClient<AIClient>('ai');
159
+ }
160
+
161
+ // Usage
162
+ import { getVibesAIClient } from '@vibesdotdev/ai/client';
163
+
164
+ const ai = await getVibesAIClient();
165
+ const response = await ai.generate({ prompt: 'Hello' });
166
+ \`\`\`
167
+
168
+ **Benefits of wrappers:**
169
+ - Type inference without generics
170
+ - Centralized error handling
171
+ - Easier refactoring if client ids change
172
+ - Better IDE autocomplete
173
+
174
+ ## Comparison: getVibesClient() vs runtime.query()
175
+
176
+ | Aspect | \`getVibesClient()\` | \`runtime.query()\` |
177
+ |--------|---------------------|---------------------|
178
+ | **Verbosity** | Concise | Verbose |
179
+ | **Type safety** | Generic \`<T>\` | Manual casting |
180
+ | **Auto-registration** | Yes | No |
181
+ | **Error messages** | Helpful | Generic |
182
+ | **Use case** | Client resolution | General kind resolution |
183
+
184
+ \`\`\`ts
185
+ // Verbose: runtime.query()
186
+ const client = await runtime
187
+ .query('runtime/client')
188
+ .withId('ai')
189
+ .resolve() as AIClient;
190
+
191
+ // Concise: getVibesClient()
192
+ const client = await getVibesClient<AIClient>('ai');
193
+ \`\`\`
194
+
195
+ **Rule of thumb:** Use \`getVibesClient()\` for client resolution, \`runtime.query()\` for other kinds (tools, providers, models, etc.).
196
+
197
+ ## Surface Detection
198
+
199
+ The helpers themselves are **surface-neutral** — they work in CLI, SSR, browser, and worker contexts. Surface detection happens at the runtime level:
200
+
201
+ \`\`\`ts
202
+ // All surfaces use the same helper
203
+ import { getVibesClient } from '@vibesdotdev/runtime-client';
204
+
205
+ const tools = await getVibesClient('tools');
206
+
207
+ // Surface is determined by runtime scope:
208
+ // - CLI: { surface: 'cli', hardware: 'consumer' }
209
+ // - SSR: { surface: 'ssr', hardware: 'consumer' }
210
+ // - Browser: { surface: 'browser', hardware: 'consumer' }
211
+ // - Worker: { surface: 'worker', hardware: 'cloud' }
212
+ \`\`\`
213
+
214
+ The runtime's scope affects **which implementation** is resolved, not **how** it's resolved:
215
+
216
+ \`\`\`ts
217
+ // In CLI surface
218
+ const runtime = getVibesRuntime();
219
+ runtime.scope; // { surface: 'cli', hardware: 'consumer' }
220
+
221
+ // In SSR surface (SvelteKit +page.server.ts)
222
+ const runtime = getVibesRuntime();
223
+ runtime.scope; // { surface: 'ssr', hardware: 'consumer' }
224
+
225
+ // Same helper, different underlying implementations
226
+ const tools = await getVibesClient('tools');
227
+ \`\`\`
228
+
229
+ See [\`runtime-client.surface\`](runtime-client.surface) for surface-specific initialization patterns.
230
+
231
+ ## WRONG patterns
232
+
233
+ :::card{title="Anti-patterns"}
234
+ - ❌ **Manual runtime.query() chains** — Use \`getVibesClient()\` for client resolution
235
+ - ❌ **Ignoring type parameters** — Always specify \`getVibesClient<T>()\` for type safety
236
+ - ❌ **Catching and swallowing errors** — Let registration errors surface; they indicate misconfiguration
237
+ - ❌ **Assuming client is cached** — Helper resolves fresh each call; client implementations cache internally
238
+ - ❌ **Using in module scope** — Call at function/call site, not top-level module scope
239
+ :::
240
+
241
+ ## Example: Service layer
242
+
243
+ \`\`\`ts
244
+ // packages/my-app/src/services/content-generator.ts
245
+ import { getVibesClient } from '@vibesdotdev/runtime-client';
246
+ import type { AIClient } from '@vibesdotdev/ai/client';
247
+ import type { ToolsClient } from '@vibesdotdev/tools/client';
248
+
249
+ export class ContentGenerator {
250
+ private aiClient?: AIClient;
251
+ private toolsClient?: ToolsClient;
252
+
253
+ async initialize(): Promise<void> {
254
+ // Lazy initialization with error handling
255
+ try {
256
+ this.aiClient = await getVibesClient<AIClient>('ai');
257
+ this.toolsClient = await getVibesClient<ToolsClient>('tools');
258
+ } catch (error) {
259
+ throw new Error(\`Failed to initialize content generator: \${error}\`);
260
+ }
261
+ }
262
+
263
+ async generateContent(topic: string): Promise<string> {
264
+ if (!this.aiClient || !this.toolsClient) {
265
+ await this.initialize();
266
+ }
267
+
268
+ // Use tools to gather context
269
+ const context = await this.toolsClient!.runTool('web-search', {
270
+ query: topic
271
+ });
272
+
273
+ // Generate content with AI
274
+ const response = await this.aiClient!.generate({
275
+ prompt: \`Write about \${topic}. Context: \${context}\`,
276
+ maxTokens: 2000
277
+ });
278
+
279
+ return response;
280
+ }
281
+ }
282
+ \`\`\`
283
+
284
+ ## Example: Testing
285
+
286
+ \`\`\`ts
287
+ // packages/my-app/src/__tests__/content-generator.test.ts
288
+ import { describe, it, expect, beforeEach } from 'bun:test';
289
+ import { getVibesRuntime, resetVibesRuntime } from '@vibesdotdev/runtime';
290
+ import { getVibesClient } from '@vibesdotdev/runtime-client';
291
+ import { aiPlugin } from '@vibesdotdev/ai';
292
+ import { toolsPlugin } from '@vibesdotdev/tools';
293
+
294
+ describe('ContentGenerator', () => {
295
+ beforeEach(async () => {
296
+ resetVibesRuntime();
297
+ const runtime = getVibesRuntime();
298
+ await runtime.registerPlugin(aiPlugin);
299
+ await runtime.registerPlugin(toolsPlugin);
300
+ });
301
+
302
+ it('generates content', async () => {
303
+ const ai = await getVibesClient('ai');
304
+ const tools = await getVibesClient('tools');
305
+
306
+ // Test with real clients
307
+ const response = await ai.generate({ prompt: 'Test' });
308
+ expect(response).toBeDefined();
309
+ });
310
+ });
311
+ \`\`\`
312
+
313
+ ## Code paths
314
+
315
+ - Helper implementation: [\`packages/runtime-client/src/helper.ts\`](https://github.com/vibesdotdev/monorepo/tree/main/packages/runtime-client/src/helper.ts)
316
+ - Plugin registration: [\`packages/runtime-client/src/plugin.ts\`](https://github.com/vibesdotdev/monorepo/tree/main/packages/runtime-client/src/plugin.ts)
317
+ - Kind definition: [\`packages/runtime-client/src/kind.ts\`](https://github.com/vibesdotdev/monorepo/tree/main/packages/runtime-client/src/kind.ts)
318
+
319
+ :::card{title="See also"}
320
+ - [\`runtime-client.api\`](runtime-client.api) — BaseRuntimeClient and extension patterns
321
+ - [\`runtime-client.surface\`](runtime-client.surface) — Surface initialization patterns
322
+ - [\`runtime.query\`](runtime.query) — Runtime query API
323
+ - [\`runtime.plugins\`](runtime.plugins) — Plugin registration and lifecycle
324
+ :::
325
+ `
326
+ },
327
+ parent: 'runtime-client',
328
+ order: 2,
329
+ tags: ['runtime-client', 'helpers', 'getVibesClient', 'resolution', 'singleton'],
330
+ surfaces: ['cli', 'web', 'in-app'],
331
+ hardware: ['consumer', 'cloud'],
332
+ enabled: true,
333
+ man: {
334
+ name: 'runtime-client.helpers — getVibesClient() helper functions',
335
+ section: 1,
336
+ synopsis: 'vibes man runtime-client.helpers',
337
+ options: [],
338
+ examples: [
339
+ {
340
+ description: 'Resolve client by id',
341
+ command: 'const ai = await getVibesClient<AIClient>("ai")'
342
+ },
343
+ {
344
+ description: 'Use typed wrapper',
345
+ command: 'const tools = await getVibesToolsClient()'
346
+ }
347
+ ],
348
+ seeAlso: ['runtime-client.api', 'runtime-client.surface', 'runtime.query']
349
+ }
350
+ };
351
+ export default descriptor;
352
+ //# sourceMappingURL=runtime-client.helpers.docs.descriptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-client.helpers.docs.descriptor.js","source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,EAAE,CAAC,oBAAoB,EAAE,wBAAwB,EAAE,eAAe,CAAC;KAC3E;CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { DocsTopicDescriptor } from './types.ts';
2
+ /**
3
+ * Descriptor for runtime-client.surface
4
+ * How surfaces (CLI, SSR, browser, worker) initialize runtime clients
5
+ */
6
+ declare const descriptor: DocsTopicDescriptor;
7
+ export default descriptor;
8
+ //# sourceMappingURL=runtime-client.surface.docs.descriptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-client.surface.docs.descriptor.d.ts","sourceRoot":"","sources":["../../src/docs/runtime-client.surface.docs.descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;GAGG;AACH,QAAA,MAAM,UAAU,EAAE,mBAycjB,CAAC;AAEF,eAAe,UAAU,CAAC"}