@vibesdotdev/client 0.1.1 → 1.0.0-rc.3
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 +21 -0
- package/README.md +24 -15
- package/dist/api-client-plugin.d.ts +4 -0
- package/dist/api-client-plugin.d.ts.map +1 -0
- package/dist/api-client-plugin.js +20 -0
- package/dist/api-client-plugin.js.map +1 -0
- package/dist/api-client.impl.d.ts +23 -0
- package/dist/api-client.impl.d.ts.map +1 -0
- package/dist/api-client.impl.js +47 -0
- package/dist/api-client.impl.js.map +1 -0
- package/dist/client.consumer.plugin.d.ts +3 -0
- package/dist/client.consumer.plugin.d.ts.map +1 -0
- package/dist/client.consumer.plugin.js +10 -0
- package/dist/client.consumer.plugin.js.map +1 -0
- package/dist/cloud.plugin.d.ts +3 -0
- package/dist/cloud.plugin.d.ts.map +1 -0
- package/dist/cloud.plugin.js +10 -0
- package/dist/cloud.plugin.js.map +1 -0
- package/dist/config/client.config.descriptor.d.ts +4 -0
- package/dist/config/client.config.descriptor.d.ts.map +1 -0
- package/dist/config/client.config.descriptor.js +32 -0
- package/dist/config/client.config.descriptor.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/settings.d.ts +9 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +25 -0
- package/dist/config/settings.js.map +1 -0
- package/dist/docs/client.api-request.docs.descriptor.d.ts +4 -0
- package/dist/docs/client.api-request.docs.descriptor.d.ts.map +1 -0
- package/dist/docs/client.api-request.docs.descriptor.js +71 -0
- package/dist/docs/client.api-request.docs.descriptor.js.map +1 -0
- package/dist/events/auth-rejected.event.d.ts +35 -0
- package/dist/events/auth-rejected.event.d.ts.map +1 -0
- package/dist/events/auth-rejected.event.js +36 -0
- package/dist/events/auth-rejected.event.js.map +1 -0
- package/dist/factory.d.ts +5 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +16 -17
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/kind-augment.d.ts +11 -0
- package/dist/kind-augment.d.ts.map +1 -0
- package/dist/kind-augment.js +2 -0
- package/dist/kind-augment.js.map +1 -0
- package/dist/lib/client/api-diagnostics.d.ts +79 -0
- package/dist/lib/client/api-diagnostics.d.ts.map +1 -0
- package/dist/lib/client/api-diagnostics.js +111 -0
- package/dist/lib/client/api-diagnostics.js.map +1 -0
- package/dist/lib/client/configured.d.ts +78 -0
- package/dist/lib/client/configured.d.ts.map +1 -0
- package/dist/lib/client/configured.js +261 -0
- package/dist/lib/client/configured.js.map +1 -0
- package/dist/lib/client/internal/auth-headers.d.ts +11 -0
- package/dist/lib/client/internal/auth-headers.d.ts.map +1 -0
- package/dist/lib/client/internal/auth-headers.js +35 -0
- package/dist/lib/client/internal/auth-headers.js.map +1 -0
- package/dist/lib/client/internal/base-client.d.ts +5 -2
- package/dist/lib/client/internal/base-client.d.ts.map +1 -1
- package/dist/lib/client/internal/base-client.js +42 -22
- package/dist/lib/client/internal/base-client.js.map +1 -1
- package/dist/lib/client/internal/base-helpers.d.ts.map +1 -1
- package/dist/lib/client/internal/base-helpers.js +20 -20
- package/dist/lib/client/internal/base-helpers.js.map +1 -1
- package/dist/lib/client/internal/base-types.d.ts +10 -5
- package/dist/lib/client/internal/base-types.d.ts.map +1 -1
- package/dist/lib/client/internal/base-types.js +5 -3
- package/dist/lib/client/internal/base-types.js.map +1 -1
- package/dist/lib/client/internal/client-values.d.ts +43 -0
- package/dist/lib/client/internal/client-values.d.ts.map +1 -0
- package/dist/lib/client/internal/client-values.js +76 -0
- package/dist/lib/client/internal/client-values.js.map +1 -0
- package/dist/lib/client/internal/endpoint.d.ts +6 -5
- package/dist/lib/client/internal/endpoint.d.ts.map +1 -1
- package/dist/lib/client/internal/endpoint.js +3 -0
- package/dist/lib/client/internal/endpoint.js.map +1 -1
- package/dist/lib/client/internal/generator.d.ts +98 -9
- package/dist/lib/client/internal/generator.d.ts.map +1 -1
- package/dist/lib/client/internal/generator.js +92 -140
- package/dist/lib/client/internal/generator.js.map +1 -1
- package/dist/lib/client/internal/request-builder.d.ts +5 -2
- package/dist/lib/client/internal/request-builder.d.ts.map +1 -1
- package/dist/lib/client/internal/request-builder.js +105 -65
- package/dist/lib/client/internal/request-builder.js.map +1 -1
- package/dist/lib/client/internal/sse-stream.d.ts +9 -5
- package/dist/lib/client/internal/sse-stream.d.ts.map +1 -1
- package/dist/lib/client/internal/sse-stream.js +96 -94
- package/dist/lib/client/internal/sse-stream.js.map +1 -1
- package/dist/lib/client/internal/timeout-signal.d.ts +8 -0
- package/dist/lib/client/internal/timeout-signal.d.ts.map +1 -0
- package/dist/lib/client/internal/timeout-signal.js +17 -0
- package/dist/lib/client/internal/timeout-signal.js.map +1 -0
- package/dist/lib/client/internal/transport/http2-fetch.d.ts +8 -0
- package/dist/lib/client/internal/transport/http2-fetch.d.ts.map +1 -0
- package/dist/lib/client/internal/transport/http2-fetch.js +17 -0
- package/dist/lib/client/internal/transport/http2-fetch.js.map +1 -0
- package/dist/lib/client/internal/vibes-client.d.ts +17 -8
- package/dist/lib/client/internal/vibes-client.d.ts.map +1 -1
- package/dist/lib/client/internal/vibes-client.js +127 -67
- package/dist/lib/client/internal/vibes-client.js.map +1 -1
- package/dist/lib/client/internal/wrap-fetch.d.ts +3 -2
- package/dist/lib/client/internal/wrap-fetch.d.ts.map +1 -1
- package/dist/lib/client/internal/wrap-fetch.js +14 -33
- package/dist/lib/client/internal/wrap-fetch.js.map +1 -1
- package/dist/lib/client/runtime-fetch.d.ts +14 -0
- package/dist/lib/client/runtime-fetch.d.ts.map +1 -0
- package/dist/lib/client/runtime-fetch.js +25 -0
- package/dist/lib/client/runtime-fetch.js.map +1 -0
- package/dist/lib/client/types.d.ts +18 -9
- package/dist/lib/client/types.d.ts.map +1 -1
- package/dist/lib/client/types.js +22 -3
- package/dist/lib/client/types.js.map +1 -1
- package/dist/plugin.d.ts +2 -18
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +7 -74
- package/dist/plugin.js.map +1 -1
- package/dist/runtime-client.d.ts +10 -0
- package/dist/runtime-client.d.ts.map +1 -0
- package/dist/runtime-client.js +14 -0
- package/dist/runtime-client.js.map +1 -0
- package/dist/schemas/auth-rejected.d.ts +12 -0
- package/dist/schemas/auth-rejected.d.ts.map +1 -0
- package/dist/schemas/auth-rejected.js +11 -0
- package/dist/schemas/auth-rejected.js.map +1 -0
- package/dist/schemas/sdk-languages.d.ts +47 -0
- package/dist/schemas/sdk-languages.d.ts.map +1 -0
- package/dist/schemas/sdk-languages.js +75 -0
- package/dist/schemas/sdk-languages.js.map +1 -0
- package/dist/schemas/settings.d.ts +14 -0
- package/dist/schemas/settings.d.ts.map +1 -0
- package/dist/schemas/settings.js +10 -0
- package/dist/schemas/settings.js.map +1 -0
- package/dist/schemas/validated-request.d.ts +19 -0
- package/dist/schemas/validated-request.d.ts.map +1 -0
- package/dist/schemas/validated-request.js +2 -0
- package/dist/schemas/validated-request.js.map +1 -0
- package/dist/schemas.d.ts +23 -8
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +8 -2
- package/dist/schemas.js.map +1 -1
- package/dist/sse-client.d.ts +17 -15
- package/dist/sse-client.d.ts.map +1 -1
- package/dist/sse-client.js +111 -91
- package/dist/sse-client.js.map +1 -1
- package/dist/svelte/client-svelte.plugin.d.ts +5 -0
- package/dist/svelte/client-svelte.plugin.d.ts.map +1 -0
- package/dist/svelte/client-svelte.plugin.js +46 -0
- package/dist/svelte/index.d.ts +3 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +2 -0
- package/dist/svelte/styles.css +8 -0
- package/dist/svelte/tool-widgets/ApiRequestToolCard.svelte +53 -0
- package/dist/svelte/tool-widgets/ApiRequestToolCard.svelte.d.ts +5 -0
- package/dist/svelte/tool-widgets/ApiRequestToolCard.svelte.d.ts.map +1 -0
- package/dist/svelte/tool-widgets/index.d.ts +2 -0
- package/dist/svelte/tool-widgets/index.d.ts.map +1 -0
- package/dist/svelte/tool-widgets/index.js +1 -0
- package/dist/tools/api-request/api-request.contract.d.ts +19 -0
- package/dist/tools/api-request/api-request.contract.d.ts.map +1 -0
- package/dist/tools/api-request/api-request.contract.js +110 -0
- package/dist/tools/api-request/api-request.contract.js.map +1 -0
- package/dist/tools/api-request/api-request.descriptor.d.ts +11 -4
- package/dist/tools/api-request/api-request.descriptor.d.ts.map +1 -1
- package/dist/tools/api-request/api-request.descriptor.js +8 -5
- package/dist/tools/api-request/api-request.descriptor.js.map +1 -1
- package/dist/tools/api-request/api-request.impl.cloud.d.ts +15 -0
- package/dist/tools/api-request/api-request.impl.cloud.d.ts.map +1 -0
- package/dist/tools/api-request/api-request.impl.cloud.js +75 -0
- package/dist/tools/api-request/api-request.impl.cloud.js.map +1 -0
- package/dist/tools/api-request/api-request.impl.consumer.d.ts +5 -3
- package/dist/tools/api-request/api-request.impl.consumer.d.ts.map +1 -1
- package/dist/tools/api-request/api-request.impl.consumer.js +27 -33
- package/dist/tools/api-request/api-request.impl.consumer.js.map +1 -1
- package/dist/tools/api-request/api-request.view.d.ts +29 -0
- package/dist/tools/api-request/api-request.view.d.ts.map +1 -0
- package/dist/tools/api-request/api-request.view.js +62 -0
- package/dist/tools/api-request/api-request.view.js.map +1 -0
- package/dist/tools/api-request/schemas/index.d.ts +12 -5
- package/dist/tools/api-request/schemas/index.d.ts.map +1 -1
- package/dist/tools/api-request/schemas/index.js +24 -6
- package/dist/tools/api-request/schemas/index.js.map +1 -1
- package/dist/tui/client-tui.plugin.d.ts +3 -0
- package/dist/tui/client-tui.plugin.d.ts.map +1 -0
- package/dist/tui/client-tui.plugin.js +32 -0
- package/dist/tui/client-tui.plugin.js.map +1 -0
- package/dist/tui/index.d.ts +2 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +2 -0
- package/dist/tui/index.js.map +1 -0
- package/dist/tui/tool-widgets/ApiRequestToolWidget.impl.tui.d.ts +17 -0
- package/dist/tui/tool-widgets/ApiRequestToolWidget.impl.tui.d.ts.map +1 -0
- package/dist/tui/tool-widgets/ApiRequestToolWidget.impl.tui.js +28 -0
- package/dist/tui/tool-widgets/ApiRequestToolWidget.impl.tui.js.map +1 -0
- package/dist/validated-request.d.ts +27 -0
- package/dist/validated-request.d.ts.map +1 -0
- package/dist/validated-request.js +119 -0
- package/dist/validated-request.js.map +1 -0
- package/package.json +188 -41
- package/dist/lib/client/internal/node/http2-fetch.node.d.ts +0 -2
- package/dist/lib/client/internal/node/http2-fetch.node.d.ts.map +0 -1
- package/dist/lib/client/internal/node/http2-fetch.node.js +0 -131
- package/dist/lib/client/internal/node/http2-fetch.node.js.map +0 -1
- package/dist/lib/client/node.d.ts +0 -5
- package/dist/lib/client/node.d.ts.map +0 -1
- package/dist/lib/client/node.js +0 -33
- package/dist/lib/client/node.js.map +0 -1
- package/dist/tools/api-request/index.d.ts +0 -5
- package/dist/tools/api-request/index.d.ts.map +0 -1
- package/dist/tools/api-request/index.js +0 -4
- package/dist/tools/api-request/index.js.map +0 -1
- package/src/factory.ts +0 -114
- package/src/index.ts +0 -15
- package/src/lib/client/core.ts +0 -13
- package/src/lib/client/internal/base-client.ts +0 -107
- package/src/lib/client/internal/base-helpers.ts +0 -74
- package/src/lib/client/internal/base-types.ts +0 -42
- package/src/lib/client/internal/endpoint.ts +0 -51
- package/src/lib/client/internal/generator.ts +0 -181
- package/src/lib/client/internal/index.ts +0 -4
- package/src/lib/client/internal/node/http2-fetch.node.ts +0 -138
- package/src/lib/client/internal/request-builder.ts +0 -147
- package/src/lib/client/internal/sse-stream.ts +0 -130
- package/src/lib/client/internal/vibes-client.ts +0 -167
- package/src/lib/client/internal/wrap-fetch.ts +0 -59
- package/src/lib/client/node.ts +0 -36
- package/src/lib/client/types.ts +0 -156
- package/src/plugin.ts +0 -104
- package/src/schemas.ts +0 -91
- package/src/sse-client.ts +0 -155
- package/src/tools/api-request/api-request.descriptor.ts +0 -28
- package/src/tools/api-request/api-request.impl.consumer.ts +0 -66
- package/src/tools/api-request/index.ts +0 -4
- package/src/tools/api-request/schemas/index.ts +0 -29
package/src/lib/client/types.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vibes Client Types
|
|
3
|
-
*
|
|
4
|
-
* Configuration, errors, and type contracts for the VibesClient HTTP API client.
|
|
5
|
-
* Extracted from libraries/vibeskit (PR #447 migration) to canonicalize as a
|
|
6
|
-
* pure-isomorphic @vibesdotdev/client surface.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/** Authentication configuration */
|
|
10
|
-
export interface AuthConfig {
|
|
11
|
-
/** Authentication type */
|
|
12
|
-
type: 'apiKey' | 'session' | 'bearer' | 'none';
|
|
13
|
-
/** Static credentials */
|
|
14
|
-
credentials?: string;
|
|
15
|
-
/** Dynamic token provider */
|
|
16
|
-
tokenProvider?: () => Promise<string | null>;
|
|
17
|
-
/** Session refresh handler for expired sessions */
|
|
18
|
-
refreshHandler?: () => Promise<AuthConfig | null>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Client lifecycle hooks */
|
|
22
|
-
export interface ClientHooks {
|
|
23
|
-
/** Called before each request */
|
|
24
|
-
beforeRequest?: (request: Request) => Promise<Request> | Request;
|
|
25
|
-
/** Called after each response */
|
|
26
|
-
afterResponse?: (response: Response) => Promise<Response> | Response;
|
|
27
|
-
/** Called on request error */
|
|
28
|
-
onError?: (error: ClientError) => Promise<void> | void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Request options */
|
|
32
|
-
export interface RequestOptions {
|
|
33
|
-
/** HTTP method */
|
|
34
|
-
method: string;
|
|
35
|
-
/** Request path (will be appended to baseUrl) */
|
|
36
|
-
path: string;
|
|
37
|
-
/** URL parameters */
|
|
38
|
-
params?: Record<string, string | number | boolean>;
|
|
39
|
-
/** Query parameters */
|
|
40
|
-
query?: Record<string, string | number | boolean | string[] | undefined>;
|
|
41
|
-
/** Request body */
|
|
42
|
-
body?: unknown;
|
|
43
|
-
/** Additional headers */
|
|
44
|
-
headers?: Record<string, string>;
|
|
45
|
-
/** Override timeout for this request */
|
|
46
|
-
timeout?: number;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Client configuration options */
|
|
50
|
-
export interface ClientConfig {
|
|
51
|
-
/** Base URL for API requests */
|
|
52
|
-
baseUrl?: string;
|
|
53
|
-
/** Authentication configuration */
|
|
54
|
-
auth?: AuthConfig;
|
|
55
|
-
/** Custom fetch implementation */
|
|
56
|
-
fetch?: typeof fetch;
|
|
57
|
-
/** Request/response hooks */
|
|
58
|
-
hooks?: ClientHooks;
|
|
59
|
-
/** Request timeout in milliseconds */
|
|
60
|
-
timeout?: number;
|
|
61
|
-
/** Enable debug logging */
|
|
62
|
-
debug?: boolean;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Client error with additional context */
|
|
66
|
-
export class ClientError extends Error {
|
|
67
|
-
constructor(
|
|
68
|
-
message: string,
|
|
69
|
-
public status?: number,
|
|
70
|
-
public response?: Response,
|
|
71
|
-
public request?: RequestOptions
|
|
72
|
-
) {
|
|
73
|
-
super(message);
|
|
74
|
-
this.name = 'ClientError';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Paginated response wrapper */
|
|
79
|
-
export interface PaginatedResponse<T> {
|
|
80
|
-
data: T[];
|
|
81
|
-
total: number;
|
|
82
|
-
page: number;
|
|
83
|
-
pageSize: number;
|
|
84
|
-
hasMore: boolean;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Standard list parameters */
|
|
88
|
-
export interface ListParams {
|
|
89
|
-
/** Page number (1-based) */
|
|
90
|
-
page?: number;
|
|
91
|
-
/** Items per page */
|
|
92
|
-
limit?: number;
|
|
93
|
-
/** Sort field */
|
|
94
|
-
sortBy?: string;
|
|
95
|
-
/** Sort direction */
|
|
96
|
-
sortOrder?: 'asc' | 'desc';
|
|
97
|
-
/** Search query */
|
|
98
|
-
search?: string;
|
|
99
|
-
/** Additional filters */
|
|
100
|
-
filters?: Record<string, unknown>;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** OpenAPI path info (generic -- no openapi-types dependency) */
|
|
104
|
-
export interface PathInfo {
|
|
105
|
-
path: string;
|
|
106
|
-
method: string;
|
|
107
|
-
operationId?: string;
|
|
108
|
-
parameters?: Record<string, unknown>[];
|
|
109
|
-
requestBody?: Record<string, unknown>;
|
|
110
|
-
responses?: Record<string, unknown>;
|
|
111
|
-
tags?: string[];
|
|
112
|
-
summary?: string;
|
|
113
|
-
description?: string;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Grouped API resources */
|
|
117
|
-
export interface APIResource {
|
|
118
|
-
name: string;
|
|
119
|
-
basePath: string;
|
|
120
|
-
operations: Map<string, PathInfo>;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Migration debt: ClientUser is an auth-domain type owned by @vibesdotdev/auth.
|
|
125
|
-
* Defined here temporarily so @vibesdotdev/kit/client consumers can migrate.
|
|
126
|
-
* Target: move to packages/auth/src/shared/client-user.ts and re-export from client/core.
|
|
127
|
-
*/
|
|
128
|
-
export interface ClientUser {
|
|
129
|
-
id: string;
|
|
130
|
-
email: string;
|
|
131
|
-
displayName?: string | null;
|
|
132
|
-
avatarUrl?: string | null;
|
|
133
|
-
isSuperuser?: boolean;
|
|
134
|
-
roles?: Array<{
|
|
135
|
-
id: string;
|
|
136
|
-
name: string;
|
|
137
|
-
description: string | null;
|
|
138
|
-
isSystemRole: boolean;
|
|
139
|
-
}>;
|
|
140
|
-
permissions?: string[];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Type helpers for schema conversion
|
|
145
|
-
*/
|
|
146
|
-
export type SchemaToType<T> = T extends { type: 'string' }
|
|
147
|
-
? string
|
|
148
|
-
: T extends { type: 'number' }
|
|
149
|
-
? number
|
|
150
|
-
: T extends { type: 'boolean' }
|
|
151
|
-
? boolean
|
|
152
|
-
: T extends { type: 'array'; items: infer I }
|
|
153
|
-
? Array<SchemaToType<I>>
|
|
154
|
-
: T extends { type: 'object'; properties: infer P }
|
|
155
|
-
? { [K in keyof P]: SchemaToType<P[K]> }
|
|
156
|
-
: unknown;
|
package/src/plugin.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { createRuntimePlugin, loader } from '@vibesdotdev/runtime';
|
|
2
|
-
import type { RuntimeDescriptor } from '@vibesdotdev/runtime/schemas/descriptor';
|
|
3
|
-
import {
|
|
4
|
-
ApiClientDescriptorSchema,
|
|
5
|
-
type ApiClientDescriptor,
|
|
6
|
-
type ApiClientImplementation,
|
|
7
|
-
type ApiStreamEvent
|
|
8
|
-
} from './schemas.ts';
|
|
9
|
-
import { vibesApiClient } from './factory.ts';
|
|
10
|
-
import type { KindContext, RuntimeKindDescriptorRecord } from '@vibesdotdev/runtime/schemas/kind';
|
|
11
|
-
import apiRequestToolDescriptor from './tools/api-request/api-request.descriptor.ts';
|
|
12
|
-
|
|
13
|
-
function isApiClientDescriptor(descriptor: RuntimeDescriptor): descriptor is ApiClientDescriptor {
|
|
14
|
-
return descriptor.kind === 'api/client' && typeof descriptor.id === 'string';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Default API client implementation.
|
|
19
|
-
*
|
|
20
|
-
* When no specific client implementation is registered for a descriptor,
|
|
21
|
-
* this default constructs a client using the descriptor's baseUrl.
|
|
22
|
-
*/
|
|
23
|
-
class DefaultApiClient implements ApiClientImplementation {
|
|
24
|
-
private client: ApiClientImplementation;
|
|
25
|
-
|
|
26
|
-
constructor(descriptor: RuntimeDescriptor, _context: KindContext) {
|
|
27
|
-
if (!isApiClientDescriptor(descriptor)) {
|
|
28
|
-
throw new Error(`Invalid api/client descriptor '${descriptor.id ?? 'unknown'}'`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this.client = vibesApiClient({
|
|
32
|
-
id: descriptor.id,
|
|
33
|
-
baseUrl: descriptor.baseUrl,
|
|
34
|
-
timeout: descriptor.timeout,
|
|
35
|
-
debug: descriptor.debug
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get<T = unknown>(endpoint: string, options?: Parameters<ApiClientImplementation['get']>[1]): Promise<T> {
|
|
40
|
-
return this.client.get<T>(endpoint, options);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
post<T = unknown>(endpoint: string, body?: unknown, options?: Parameters<ApiClientImplementation['post']>[2]): Promise<T> {
|
|
44
|
-
return this.client.post<T>(endpoint, body, options);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
put<T = unknown>(endpoint: string, body?: unknown, options?: Parameters<ApiClientImplementation['put']>[2]): Promise<T> {
|
|
48
|
-
return this.client.put<T>(endpoint, body, options);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
patch<T = unknown>(endpoint: string, body?: unknown, options?: Parameters<ApiClientImplementation['patch']>[2]): Promise<T> {
|
|
52
|
-
return this.client.patch<T>(endpoint, body, options);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
delete<T = unknown>(endpoint: string, options?: Parameters<ApiClientImplementation['delete']>[1]): Promise<T> {
|
|
56
|
-
return this.client.delete<T>(endpoint, options);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
request<T = unknown>(endpoint: string, options?: Parameters<ApiClientImplementation['request']>[1]): Promise<T> {
|
|
60
|
-
return this.client.request<T>(endpoint, options);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
stream<T = unknown>(
|
|
64
|
-
endpoint: string,
|
|
65
|
-
options?: Parameters<ApiClientImplementation['stream']>[1]
|
|
66
|
-
): AsyncIterableIterator<ApiStreamEvent<T>> {
|
|
67
|
-
return this.client.stream<T>(endpoint, options) as AsyncIterableIterator<ApiStreamEvent<T>>;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const apiClientKind = {
|
|
72
|
-
id: 'api/client',
|
|
73
|
-
descriptorSchema: ApiClientDescriptorSchema,
|
|
74
|
-
defaultImplementation: DefaultApiClient
|
|
75
|
-
} satisfies RuntimeKindDescriptorRecord<ApiClientImplementation>;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Client plugin — registers the `api/client` kind with the runtime.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* import { getVibesRuntime } from '@vibesdotdev/runtime';
|
|
83
|
-
* import clientPlugin from '@vibesdotdev/client/plugin';
|
|
84
|
-
*
|
|
85
|
-
* const runtime = getVibesRuntime();
|
|
86
|
-
* await runtime.registerPlugin(clientPlugin);
|
|
87
|
-
*
|
|
88
|
-
* // Query a registered API client
|
|
89
|
-
* const authClient = await runtime.query('api/client').withId('auth').resolve();
|
|
90
|
-
* await authClient.get('/api/health');
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
export default createRuntimePlugin({
|
|
94
|
-
id: 'client',
|
|
95
|
-
name: 'API Client Module',
|
|
96
|
-
description: 'Runtime API client kind with environment-aware factories',
|
|
97
|
-
kinds: [apiClientKind],
|
|
98
|
-
descriptors: [apiRequestToolDescriptor],
|
|
99
|
-
loaders: [
|
|
100
|
-
loader('api-request', { kind: 'tools/tool', scope: 'consumer' }, () =>
|
|
101
|
-
import('./tools/api-request/api-request.impl.consumer.js')
|
|
102
|
-
)
|
|
103
|
-
]
|
|
104
|
-
});
|
package/src/schemas.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import * as z from 'zod/v4';
|
|
2
|
-
import {
|
|
3
|
-
RuntimeDescriptorSchema,
|
|
4
|
-
type RuntimeDescriptor
|
|
5
|
-
} from '@vibesdotdev/runtime/schemas/descriptor';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* API Client descriptor — metadata for a registered API client asset.
|
|
9
|
-
*/
|
|
10
|
-
export interface ApiClientDescriptor extends RuntimeDescriptor {
|
|
11
|
-
kind: 'api/client';
|
|
12
|
-
/** Base URL for this client's API */
|
|
13
|
-
baseUrl?: string;
|
|
14
|
-
/** Default timeout in milliseconds */
|
|
15
|
-
timeout?: number;
|
|
16
|
-
/** Whether to enable debug logging */
|
|
17
|
-
debug?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const ApiClientDescriptorSchema = RuntimeDescriptorSchema.extend({
|
|
21
|
-
kind: z.literal('api/client'),
|
|
22
|
-
baseUrl: z.string().optional(),
|
|
23
|
-
timeout: z.number().int().positive().optional(),
|
|
24
|
-
debug: z.boolean().optional()
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* API Client implementation interface.
|
|
29
|
-
*
|
|
30
|
-
* Any runtime API client implementation must satisfy this contract.
|
|
31
|
-
*/
|
|
32
|
-
export interface ApiClientImplementation {
|
|
33
|
-
/** Make a GET request */
|
|
34
|
-
get<T = unknown>(endpoint: string, options?: ApiRequestOptions): Promise<T>;
|
|
35
|
-
/** Make a POST request */
|
|
36
|
-
post<T = unknown>(endpoint: string, body?: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
37
|
-
/** Make a PUT request */
|
|
38
|
-
put<T = unknown>(endpoint: string, body?: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
39
|
-
/** Make a PATCH request */
|
|
40
|
-
patch<T = unknown>(endpoint: string, body?: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
41
|
-
/** Make a DELETE request */
|
|
42
|
-
delete<T = unknown>(endpoint: string, options?: ApiRequestOptions): Promise<T>;
|
|
43
|
-
/** Make a generic request */
|
|
44
|
-
request<T = unknown>(
|
|
45
|
-
endpoint: string,
|
|
46
|
-
options?: ApiRequestOptions & { method?: string; body?: unknown }
|
|
47
|
-
): Promise<T>;
|
|
48
|
-
/**
|
|
49
|
-
* Stream Server-Sent Events from an endpoint.
|
|
50
|
-
*
|
|
51
|
-
* Yields parsed SSE frames as they arrive. Each frame has already been
|
|
52
|
-
* split into event/data/id/retry fields and the data payload is
|
|
53
|
-
* JSON-parsed when possible. Returning from the generator — or the
|
|
54
|
-
* server closing the stream — ends iteration; an explicit `[DONE]`
|
|
55
|
-
* sentinel in the data stream also terminates.
|
|
56
|
-
*
|
|
57
|
-
* Use this instead of manually parsing SSE-wrapped POST bodies — the
|
|
58
|
-
* raw-fetch workaround (line-split + regex for `data: ...` lines) is
|
|
59
|
-
* brittle and fails on multi-line data, retry hints, and reconnects.
|
|
60
|
-
*/
|
|
61
|
-
stream<T = unknown>(
|
|
62
|
-
endpoint: string,
|
|
63
|
-
options?: ApiStreamOptions
|
|
64
|
-
): AsyncIterableIterator<ApiStreamEvent<T>>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface ApiRequestOptions {
|
|
68
|
-
query?: Record<string, string | number | boolean | string[] | undefined>;
|
|
69
|
-
headers?: Record<string, string>;
|
|
70
|
-
timeout?: number;
|
|
71
|
-
params?: Record<string, string | number | boolean>;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface ApiStreamOptions extends ApiRequestOptions {
|
|
75
|
-
method?: string;
|
|
76
|
-
body?: unknown;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* A single Server-Sent Event frame.
|
|
81
|
-
*
|
|
82
|
-
* `data` is JSON-parsed when the frame payload is valid JSON, otherwise
|
|
83
|
-
* the raw string is returned. `event`, `id`, and `retry` map to the
|
|
84
|
-
* corresponding SSE fields when present.
|
|
85
|
-
*/
|
|
86
|
-
export interface ApiStreamEvent<T = unknown> {
|
|
87
|
-
event?: string;
|
|
88
|
-
data: T;
|
|
89
|
-
id?: string;
|
|
90
|
-
retry?: number;
|
|
91
|
-
}
|
package/src/sse-client.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client-side SSE (Server-Sent Events) client.
|
|
3
|
-
*
|
|
4
|
-
* Provides a typed interface for connecting to SSE endpoints,
|
|
5
|
-
* handling reconnection, and dispatching events.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export type SSEConnectionStatus =
|
|
9
|
-
| 'connecting'
|
|
10
|
-
| 'connected'
|
|
11
|
-
| 'reconnecting'
|
|
12
|
-
| 'disconnected'
|
|
13
|
-
| 'error';
|
|
14
|
-
|
|
15
|
-
export interface SSEClientOptions {
|
|
16
|
-
url: string;
|
|
17
|
-
reconnectDelay?: number;
|
|
18
|
-
maxReconnectAttempts?: number;
|
|
19
|
-
onStatusChange?: (status: SSEConnectionStatus) => void;
|
|
20
|
-
onError?: (error: string) => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type EventHandler = (data: unknown) => void;
|
|
24
|
-
|
|
25
|
-
export class SSEClient {
|
|
26
|
-
private url: string;
|
|
27
|
-
private reconnectDelay: number;
|
|
28
|
-
private maxReconnectAttempts: number;
|
|
29
|
-
private onStatusChange?: (status: SSEConnectionStatus) => void;
|
|
30
|
-
private onError?: (error: string) => void;
|
|
31
|
-
|
|
32
|
-
private eventSource: EventSource | null = null;
|
|
33
|
-
private handlers = new Map<string, Set<EventHandler>>();
|
|
34
|
-
private reconnectAttempts = 0;
|
|
35
|
-
private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
|
36
|
-
private _status: SSEConnectionStatus = 'disconnected';
|
|
37
|
-
|
|
38
|
-
constructor(options: SSEClientOptions) {
|
|
39
|
-
this.url = options.url;
|
|
40
|
-
this.reconnectDelay = options.reconnectDelay ?? 5000;
|
|
41
|
-
this.maxReconnectAttempts = options.maxReconnectAttempts ?? 5;
|
|
42
|
-
this.onStatusChange = options.onStatusChange;
|
|
43
|
-
this.onError = options.onError;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get status(): SSEConnectionStatus {
|
|
47
|
-
return this._status;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
connect(): void {
|
|
51
|
-
this.setStatus('connecting');
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
const EventSourceCtor = globalThis.EventSource as {
|
|
55
|
-
new (url: string): EventSource;
|
|
56
|
-
};
|
|
57
|
-
this.eventSource = new EventSourceCtor(this.url);
|
|
58
|
-
|
|
59
|
-
this.eventSource.onopen = () => {
|
|
60
|
-
this.reconnectAttempts = 0;
|
|
61
|
-
this.setStatus('connected');
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
this.eventSource.onerror = () => {
|
|
65
|
-
const error = `SSE connection error`;
|
|
66
|
-
this.onError?.(error);
|
|
67
|
-
|
|
68
|
-
if (this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
69
|
-
this.setStatus('reconnecting');
|
|
70
|
-
this.reconnectAttempts++;
|
|
71
|
-
this.scheduleReconnect();
|
|
72
|
-
} else {
|
|
73
|
-
this.setStatus('error');
|
|
74
|
-
this.cleanup();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// Dispatch events to registered handlers
|
|
79
|
-
this.eventSource.onmessage = (event) => {
|
|
80
|
-
this.dispatch('message', event.data);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// Listen for named events by iterating registered handlers
|
|
84
|
-
for (const eventName of this.handlers.keys()) {
|
|
85
|
-
if (eventName === 'message') continue;
|
|
86
|
-
this.eventSource.addEventListener(eventName, (event) => {
|
|
87
|
-
try {
|
|
88
|
-
const data = JSON.parse((event as MessageEvent).data);
|
|
89
|
-
this.dispatch(eventName, data);
|
|
90
|
-
} catch {
|
|
91
|
-
this.dispatch(eventName, (event as MessageEvent).data);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
} catch (e) {
|
|
96
|
-
const error = e instanceof Error ? e.message : 'Failed to create SSE connection';
|
|
97
|
-
this.onError?.(error);
|
|
98
|
-
this.setStatus('error');
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
disconnect(): void {
|
|
103
|
-
this.cleanup();
|
|
104
|
-
this.setStatus('disconnected');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
on(event: string, handler: EventHandler): () => void {
|
|
108
|
-
if (!this.handlers.has(event)) {
|
|
109
|
-
this.handlers.set(event, new Set());
|
|
110
|
-
}
|
|
111
|
-
this.handlers.get(event)!.add(handler);
|
|
112
|
-
|
|
113
|
-
// Return unsubscribe function
|
|
114
|
-
return () => {
|
|
115
|
-
this.handlers.get(event)?.delete(handler);
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private dispatch(event: string, data: unknown): void {
|
|
120
|
-
this.handlers.get(event)?.forEach((handler) => {
|
|
121
|
-
try {
|
|
122
|
-
handler(data);
|
|
123
|
-
} catch (e) {
|
|
124
|
-
console.error(`[SSEClient] Error in handler for "${event}":`, e);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private setStatus(status: SSEConnectionStatus): void {
|
|
130
|
-
this._status = status;
|
|
131
|
-
this.onStatusChange?.(status);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private scheduleReconnect(): void {
|
|
135
|
-
if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
|
|
136
|
-
this.reconnectTimer = setTimeout(() => {
|
|
137
|
-
this.connect();
|
|
138
|
-
}, this.reconnectDelay);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private cleanup(): void {
|
|
142
|
-
if (this.reconnectTimer) {
|
|
143
|
-
clearTimeout(this.reconnectTimer);
|
|
144
|
-
this.reconnectTimer = null;
|
|
145
|
-
}
|
|
146
|
-
if (this.eventSource) {
|
|
147
|
-
this.eventSource.close();
|
|
148
|
-
this.eventSource = null;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function createSSEClient(options: SSEClientOptions): SSEClient {
|
|
154
|
-
return new SSEClient(options);
|
|
155
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* api-request Tool Descriptor
|
|
3
|
-
*
|
|
4
|
-
* Metadata for the api-request tool. Safe to import anywhere.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createRuntimeAsset } from '@vibesdotdev/runtime/factory';
|
|
8
|
-
import { apiRequestInputSchema, apiRequestOutputSchema } from './schemas/index.ts';
|
|
9
|
-
|
|
10
|
-
export default createRuntimeAsset({
|
|
11
|
-
kind: 'tools/tool',
|
|
12
|
-
id: 'api-request',
|
|
13
|
-
name: 'API Request',
|
|
14
|
-
description: 'Make an authenticated API request to any Vibes endpoint.',
|
|
15
|
-
mcpDescription: 'Make authenticated API request to Vibes endpoints. Ex: {method:"GET",path:"/api/health"}.',
|
|
16
|
-
hardware: ['consumer'],
|
|
17
|
-
purpose: ['direct', 'worker', 'mcp', 'agent'],
|
|
18
|
-
category: 'execution',
|
|
19
|
-
subcategory: 'api-request',
|
|
20
|
-
tags: ['api', 'network'],
|
|
21
|
-
safety: 'write',
|
|
22
|
-
requiresApproval: true,
|
|
23
|
-
permissions: ['canAccessNetwork'],
|
|
24
|
-
schemas: {
|
|
25
|
-
input: apiRequestInputSchema,
|
|
26
|
-
output: apiRequestOutputSchema
|
|
27
|
-
}
|
|
28
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* api-request Tool Implementation (Consumer)
|
|
3
|
-
*
|
|
4
|
-
* Consumer-scoped implementation for making authenticated API requests.
|
|
5
|
-
* Resolves the `api/client` runtime kind and delegates to its `.request()`.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { VibesRuntime, ToolCallContext } from '@vibesdotdev/runtime';
|
|
9
|
-
import type { ApiClientImplementation } from '../../schemas.ts';
|
|
10
|
-
import type { ApiRequestInput, ApiRequestOutput } from './schemas/index.ts';
|
|
11
|
-
|
|
12
|
-
async function resolveApiClient(runtime: VibesRuntime): Promise<ApiClientImplementation> {
|
|
13
|
-
try {
|
|
14
|
-
const apiClient = (await runtime.query('api/client').resolve()) as
|
|
15
|
-
| ApiClientImplementation
|
|
16
|
-
| undefined;
|
|
17
|
-
if (apiClient) {
|
|
18
|
-
return apiClient;
|
|
19
|
-
}
|
|
20
|
-
} catch {
|
|
21
|
-
// Query failed, fall through
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
throw new Error(
|
|
25
|
-
'API client not available in runtime context. Ensure api/client kind is registered.'
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default {
|
|
30
|
-
async execute(
|
|
31
|
-
input: ApiRequestInput,
|
|
32
|
-
runtime: VibesRuntime,
|
|
33
|
-
_ctx: ToolCallContext
|
|
34
|
-
): Promise<ApiRequestOutput> {
|
|
35
|
-
const method = input.method;
|
|
36
|
-
const path = input.path;
|
|
37
|
-
const query = input.query ?? {};
|
|
38
|
-
const body = input.body ?? undefined;
|
|
39
|
-
const headers = input.headers ?? {};
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const apiClient = await resolveApiClient(runtime);
|
|
43
|
-
|
|
44
|
-
const response = await apiClient.request(path, {
|
|
45
|
-
method,
|
|
46
|
-
query,
|
|
47
|
-
body,
|
|
48
|
-
headers
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
status: 'success',
|
|
53
|
-
response
|
|
54
|
-
};
|
|
55
|
-
} catch (error) {
|
|
56
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
57
|
-
return {
|
|
58
|
-
status: 'error',
|
|
59
|
-
error: {
|
|
60
|
-
message,
|
|
61
|
-
code: 'API_REQUEST_FAILED'
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { default as apiRequestToolDescriptor } from './api-request.descriptor.ts';
|
|
2
|
-
export { default as apiRequestToolImplementation } from './api-request.impl.consumer.ts';
|
|
3
|
-
export { apiRequestInputSchema, apiRequestOutputSchema } from './schemas/index.ts';
|
|
4
|
-
export type { ApiRequestInput, ApiRequestOutput } from './schemas/index.ts';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API Request Tool Schemas
|
|
3
|
-
*
|
|
4
|
-
* Input/output schemas for the api-request tool.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as z from 'zod/v4';
|
|
8
|
-
|
|
9
|
-
export const apiRequestInputSchema = z.object({
|
|
10
|
-
method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']),
|
|
11
|
-
path: z.string().min(1),
|
|
12
|
-
query: z.record(z.string(), z.any()).optional(),
|
|
13
|
-
body: z.any().optional(),
|
|
14
|
-
headers: z.record(z.string(), z.string()).optional()
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export const apiRequestOutputSchema = z.object({
|
|
18
|
-
status: z.enum(['success', 'error']),
|
|
19
|
-
response: z.unknown().optional(),
|
|
20
|
-
error: z
|
|
21
|
-
.object({
|
|
22
|
-
message: z.string(),
|
|
23
|
-
code: z.string().optional()
|
|
24
|
-
})
|
|
25
|
-
.optional()
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export type ApiRequestInput = z.infer<typeof apiRequestInputSchema>;
|
|
29
|
-
export type ApiRequestOutput = z.infer<typeof apiRequestOutputSchema>;
|