services-as-software 0.1.0 → 2.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.
- package/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +10 -0
- package/README.md +235 -225
- package/dist/client.d.ts +25 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +103 -0
- package/dist/client.js.map +1 -0
- package/dist/endpoint.d.ts +102 -0
- package/dist/endpoint.d.ts.map +1 -0
- package/dist/endpoint.js +96 -0
- package/dist/endpoint.js.map +1 -0
- package/dist/entities/billing.d.ts +60 -0
- package/dist/entities/billing.d.ts.map +1 -0
- package/dist/entities/billing.js +954 -0
- package/dist/entities/billing.js.map +1 -0
- package/dist/entities/customers.d.ts +45 -0
- package/dist/entities/customers.d.ts.map +1 -0
- package/dist/entities/customers.js +679 -0
- package/dist/entities/customers.js.map +1 -0
- package/dist/entities/delivery.d.ts +59 -0
- package/dist/entities/delivery.d.ts.map +1 -0
- package/dist/entities/delivery.js +890 -0
- package/dist/entities/delivery.js.map +1 -0
- package/dist/entities/index.d.ts +114 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +89 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/operations.d.ts +59 -0
- package/dist/entities/operations.d.ts.map +1 -0
- package/dist/entities/operations.js +1010 -0
- package/dist/entities/operations.js.map +1 -0
- package/dist/entities/orchestration.d.ts +52 -0
- package/dist/entities/orchestration.d.ts.map +1 -0
- package/dist/entities/orchestration.js +883 -0
- package/dist/entities/orchestration.js.map +1 -0
- package/dist/entities/services.d.ts +50 -0
- package/dist/entities/services.d.ts.map +1 -0
- package/dist/entities/services.js +805 -0
- package/dist/entities/services.js.map +1 -0
- package/dist/helpers.d.ts +362 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +400 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +17 -215
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -172
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +85 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +158 -0
- package/dist/provider.js.map +1 -0
- package/dist/service.d.ts +43 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +206 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +469 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/examples/client-usage.ts +82 -0
- package/examples/translation-service.ts +227 -0
- package/package.json +24 -38
- package/src/client.ts +132 -0
- package/src/endpoint.ts +144 -0
- package/src/entities/billing.ts +1037 -0
- package/src/entities/customers.ts +740 -0
- package/src/entities/delivery.ts +974 -0
- package/src/entities/index.ts +157 -0
- package/src/entities/operations.ts +1099 -0
- package/src/entities/orchestration.ts +956 -0
- package/src/entities/services.ts +872 -0
- package/src/helpers.ts +474 -0
- package/src/index.ts +97 -0
- package/src/provider.ts +183 -0
- package/src/service.test.ts +195 -0
- package/src/service.ts +266 -0
- package/src/types.ts +543 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,cAAc,CAAA;AAGpF,MAAM,MAAM,UAAU,GAAG,YAAY,CAAA;AAGrC,KAAK,UAAU,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAA;AAE/B;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,OAAO,GACP,SAAS,GACT,cAAc,GACd,QAAQ,GACR,aAAa,GACb,QAAQ,CAAA;AAEZ;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE7F;;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AACH,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ,wBAAwB;IACxB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAEnB,qBAAqB;IACrB,IAAI,CAAC,EAAE;QACL,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAA;QAC3C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACpC,CAAA;IAED,qBAAqB;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEhC,6BAA6B;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Using the Service Client
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to connect to a remote service using the Client
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Client, Provider, providers } from '../src/index.js'
|
|
8
|
+
|
|
9
|
+
// Connect to a service using a direct URL
|
|
10
|
+
const translationClient = Client({
|
|
11
|
+
url: 'https://api.example.com/translation',
|
|
12
|
+
auth: {
|
|
13
|
+
type: 'api-key',
|
|
14
|
+
credentials: {
|
|
15
|
+
apiKey: 'your-api-key-here',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// Use the client
|
|
21
|
+
async function useDirectClient() {
|
|
22
|
+
const result = await translationClient.do('translate', {
|
|
23
|
+
text: 'Hello, world!',
|
|
24
|
+
to: 'es',
|
|
25
|
+
})
|
|
26
|
+
console.log('Translation:', result)
|
|
27
|
+
|
|
28
|
+
// Get a quote
|
|
29
|
+
const quote = await translationClient.quote(
|
|
30
|
+
{ text: 'Large document...', to: 'es' },
|
|
31
|
+
1000
|
|
32
|
+
)
|
|
33
|
+
console.log('Quote:', quote)
|
|
34
|
+
|
|
35
|
+
// Subscribe to a plan
|
|
36
|
+
const subscription = await translationClient.subscribe('pro')
|
|
37
|
+
console.log('Subscription:', subscription)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Use a provider to access multiple services
|
|
41
|
+
const awsProvider = providers.aws({
|
|
42
|
+
accessKeyId: 'your-access-key',
|
|
43
|
+
secretAccessKey: 'your-secret-key',
|
|
44
|
+
region: 'us-east-1',
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
async function useProvider() {
|
|
48
|
+
// Get the translate service from AWS
|
|
49
|
+
const translate = awsProvider.service('translate')
|
|
50
|
+
|
|
51
|
+
const result = await translate.do('translate', {
|
|
52
|
+
text: 'Hello, world!',
|
|
53
|
+
sourceLang: 'en',
|
|
54
|
+
targetLang: 'es',
|
|
55
|
+
})
|
|
56
|
+
console.log('AWS Translation:', result)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Create a custom provider
|
|
60
|
+
const customProvider = Provider({
|
|
61
|
+
name: 'My Company',
|
|
62
|
+
baseUrl: 'https://api.mycompany.com',
|
|
63
|
+
auth: {
|
|
64
|
+
type: 'jwt',
|
|
65
|
+
credentials: {
|
|
66
|
+
token: 'your-jwt-token',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
services: ['translation', 'summarization', 'sentiment'],
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
async function useCustomProvider() {
|
|
73
|
+
const translation = customProvider.service('translation')
|
|
74
|
+
const result = await translation.do('translate', {
|
|
75
|
+
text: 'Hello',
|
|
76
|
+
to: 'fr',
|
|
77
|
+
})
|
|
78
|
+
console.log('Custom provider result:', result)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Export examples
|
|
82
|
+
export { useDirectClient, useProvider, useCustomProvider }
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Translation Service
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to create a translation service with:
|
|
5
|
+
* - Multiple endpoints (translate, detect language)
|
|
6
|
+
* - Per-use pricing
|
|
7
|
+
* - Rate limiting
|
|
8
|
+
* - Usage tracking
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Service, Endpoint, POST, GET } from '../src/index.js'
|
|
12
|
+
|
|
13
|
+
// Define the translation service
|
|
14
|
+
const translationService = Service({
|
|
15
|
+
name: 'translation-service',
|
|
16
|
+
version: '1.0.0',
|
|
17
|
+
description: 'AI-powered translation service',
|
|
18
|
+
status: 'active',
|
|
19
|
+
|
|
20
|
+
// Default pricing for all endpoints
|
|
21
|
+
pricing: {
|
|
22
|
+
model: 'per-use',
|
|
23
|
+
pricePerUnit: 0.01, // $0.01 per character
|
|
24
|
+
currency: 'USD',
|
|
25
|
+
freeTier: {
|
|
26
|
+
units: 10000, // 10,000 free characters per month
|
|
27
|
+
resetInterval: 'monthly',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
// Service endpoints
|
|
32
|
+
endpoints: [
|
|
33
|
+
POST({
|
|
34
|
+
name: 'translate',
|
|
35
|
+
description: 'Translate text between languages',
|
|
36
|
+
path: '/translate',
|
|
37
|
+
input: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
text: { type: 'string', description: 'Text to translate' },
|
|
41
|
+
from: { type: 'string', description: 'Source language code (optional)' },
|
|
42
|
+
to: { type: 'string', description: 'Target language code' },
|
|
43
|
+
},
|
|
44
|
+
required: ['text', 'to'],
|
|
45
|
+
additionalProperties: false,
|
|
46
|
+
},
|
|
47
|
+
output: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: {
|
|
50
|
+
translatedText: { type: 'string', description: 'Translated text' },
|
|
51
|
+
sourceLanguage: { type: 'string', description: 'Detected or specified source language' },
|
|
52
|
+
confidence: { type: 'number', description: 'Translation confidence (0-1)' },
|
|
53
|
+
},
|
|
54
|
+
required: ['translatedText', 'sourceLanguage', 'confidence'],
|
|
55
|
+
additionalProperties: false,
|
|
56
|
+
},
|
|
57
|
+
handler: async (input, context) => {
|
|
58
|
+
// Track usage for billing
|
|
59
|
+
if (context?.usage && context.customerId) {
|
|
60
|
+
await context.usage.track({
|
|
61
|
+
customerId: context.customerId,
|
|
62
|
+
resource: 'translate',
|
|
63
|
+
quantity: input.text.length, // Charge per character
|
|
64
|
+
timestamp: new Date(),
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// In a real implementation, this would call an AI translation API
|
|
69
|
+
return {
|
|
70
|
+
translatedText: `[Translated to ${input.to}] ${input.text}`,
|
|
71
|
+
sourceLanguage: input.from || 'auto-detected',
|
|
72
|
+
confidence: 0.95,
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
rateLimit: {
|
|
76
|
+
requests: 100,
|
|
77
|
+
window: 60000, // 100 requests per minute
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
|
|
81
|
+
GET({
|
|
82
|
+
name: 'detect',
|
|
83
|
+
description: 'Detect the language of text',
|
|
84
|
+
path: '/detect',
|
|
85
|
+
input: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
text: { type: 'string', description: 'Text to analyze' },
|
|
89
|
+
},
|
|
90
|
+
required: ['text'],
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
},
|
|
93
|
+
output: {
|
|
94
|
+
type: 'object',
|
|
95
|
+
properties: {
|
|
96
|
+
language: { type: 'string', description: 'Detected language code' },
|
|
97
|
+
confidence: { type: 'number', description: 'Detection confidence (0-1)' },
|
|
98
|
+
},
|
|
99
|
+
required: ['language', 'confidence'],
|
|
100
|
+
additionalProperties: false,
|
|
101
|
+
},
|
|
102
|
+
handler: async (input) => {
|
|
103
|
+
// Language detection logic
|
|
104
|
+
return {
|
|
105
|
+
language: 'en',
|
|
106
|
+
confidence: 0.98,
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
pricing: {
|
|
110
|
+
model: 'per-use',
|
|
111
|
+
pricePerUnit: 0.001, // $0.001 per detection (cheaper than translation)
|
|
112
|
+
currency: 'USD',
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
|
|
116
|
+
Endpoint({
|
|
117
|
+
name: 'languages',
|
|
118
|
+
description: 'Get supported languages',
|
|
119
|
+
method: 'GET',
|
|
120
|
+
path: '/languages',
|
|
121
|
+
handler: async () => {
|
|
122
|
+
return {
|
|
123
|
+
languages: [
|
|
124
|
+
{ code: 'en', name: 'English' },
|
|
125
|
+
{ code: 'es', name: 'Spanish' },
|
|
126
|
+
{ code: 'fr', name: 'French' },
|
|
127
|
+
{ code: 'de', name: 'German' },
|
|
128
|
+
{ code: 'ja', name: 'Japanese' },
|
|
129
|
+
{ code: 'zh', name: 'Chinese' },
|
|
130
|
+
],
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
requiresAuth: false, // Public endpoint
|
|
134
|
+
}),
|
|
135
|
+
],
|
|
136
|
+
|
|
137
|
+
// Subscription plans
|
|
138
|
+
plans: [
|
|
139
|
+
{
|
|
140
|
+
id: 'starter',
|
|
141
|
+
name: 'Starter Plan',
|
|
142
|
+
description: 'For individual developers',
|
|
143
|
+
pricing: {
|
|
144
|
+
model: 'subscription',
|
|
145
|
+
basePrice: 9.99,
|
|
146
|
+
currency: 'USD',
|
|
147
|
+
interval: 'monthly',
|
|
148
|
+
},
|
|
149
|
+
entitlements: ['api-access', 'basic-support'],
|
|
150
|
+
features: [
|
|
151
|
+
'100,000 characters/month',
|
|
152
|
+
'Email support',
|
|
153
|
+
'Basic languages',
|
|
154
|
+
],
|
|
155
|
+
limits: {
|
|
156
|
+
characters: 100000,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: 'pro',
|
|
161
|
+
name: 'Pro Plan',
|
|
162
|
+
description: 'For growing businesses',
|
|
163
|
+
pricing: {
|
|
164
|
+
model: 'subscription',
|
|
165
|
+
basePrice: 49.99,
|
|
166
|
+
currency: 'USD',
|
|
167
|
+
interval: 'monthly',
|
|
168
|
+
},
|
|
169
|
+
entitlements: ['api-access', 'priority-support', 'advanced-features'],
|
|
170
|
+
features: [
|
|
171
|
+
'1,000,000 characters/month',
|
|
172
|
+
'Priority support',
|
|
173
|
+
'All languages',
|
|
174
|
+
'Custom models',
|
|
175
|
+
],
|
|
176
|
+
limits: {
|
|
177
|
+
characters: 1000000,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
|
|
182
|
+
// KPIs
|
|
183
|
+
kpis: [
|
|
184
|
+
{
|
|
185
|
+
id: 'translations-per-day',
|
|
186
|
+
name: 'Translations per Day',
|
|
187
|
+
description: 'Number of translation requests processed daily',
|
|
188
|
+
calculate: async () => {
|
|
189
|
+
// In a real implementation, query the database
|
|
190
|
+
return 1247
|
|
191
|
+
},
|
|
192
|
+
target: 1000,
|
|
193
|
+
unit: 'requests',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: 'average-confidence',
|
|
197
|
+
name: 'Average Translation Confidence',
|
|
198
|
+
description: 'Average confidence score across all translations',
|
|
199
|
+
calculate: async () => {
|
|
200
|
+
return 0.94
|
|
201
|
+
},
|
|
202
|
+
target: 0.95,
|
|
203
|
+
unit: 'score',
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
// Example usage
|
|
209
|
+
async function example() {
|
|
210
|
+
// Call the translate endpoint
|
|
211
|
+
const result = await translationService.call('translate', {
|
|
212
|
+
text: 'Hello, world!',
|
|
213
|
+
to: 'es',
|
|
214
|
+
})
|
|
215
|
+
console.log('Translation result:', result)
|
|
216
|
+
|
|
217
|
+
// Get KPIs
|
|
218
|
+
const kpis = await translationService.kpis()
|
|
219
|
+
console.log('KPIs:', kpis)
|
|
220
|
+
|
|
221
|
+
// Subscribe to a plan
|
|
222
|
+
const subscription = await translationService.subscribe('pro')
|
|
223
|
+
console.log('Subscription:', subscription)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Export the service
|
|
227
|
+
export { translationService }
|
package/package.json
CHANGED
|
@@ -1,49 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "services-as-software",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "
|
|
5
|
-
"keywords": [
|
|
6
|
-
"services",
|
|
7
|
-
"business",
|
|
8
|
-
"pricing",
|
|
9
|
-
"objectives",
|
|
10
|
-
"key results",
|
|
11
|
-
"agentic"
|
|
12
|
-
],
|
|
13
|
-
"homepage": "https://mdx.org.ai",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Primitives for building AI-powered services that operate as software",
|
|
14
5
|
"type": "module",
|
|
15
6
|
"main": "dist/index.js",
|
|
16
|
-
"module": "dist/index.js",
|
|
17
7
|
"types": "dist/index.d.ts",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
21
14
|
"scripts": {
|
|
22
|
-
"build": "
|
|
23
|
-
"dev": "
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"test": "vitest",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"lint": "eslint .",
|
|
20
|
+
"clean": "rm -rf dist"
|
|
28
21
|
},
|
|
29
22
|
"dependencies": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"business-as-code": "0.0.2",
|
|
35
|
-
"tsup": "^8.0.1",
|
|
36
|
-
"typescript": "^5.2.2",
|
|
37
|
-
"vitest": "^0.34.6"
|
|
23
|
+
"ai-database": "workspace:*",
|
|
24
|
+
"ai-functions": "workspace:*",
|
|
25
|
+
"digital-workers": "workspace:*",
|
|
26
|
+
"rpc.do": "^0.1.0"
|
|
38
27
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"url": "https://github.com/drivly/ai/issues"
|
|
46
|
-
},
|
|
47
|
-
"author": "Drivly",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"services",
|
|
30
|
+
"software",
|
|
31
|
+
"ai",
|
|
32
|
+
"primitives"
|
|
33
|
+
],
|
|
48
34
|
"license": "MIT"
|
|
49
35
|
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service client for connecting to remote services
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
ServiceClient,
|
|
7
|
+
ClientConfig,
|
|
8
|
+
Order,
|
|
9
|
+
Quote,
|
|
10
|
+
Subscription,
|
|
11
|
+
Notification,
|
|
12
|
+
OKRDefinition,
|
|
13
|
+
JSONSchema,
|
|
14
|
+
} from './types.js'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create a client to connect to a remote service
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const client = Client({
|
|
22
|
+
* url: 'https://api.example.com/translation',
|
|
23
|
+
* auth: {
|
|
24
|
+
* type: 'api-key',
|
|
25
|
+
* credentials: { apiKey: process.env.API_KEY },
|
|
26
|
+
* },
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* const result = await client.do('translate', {
|
|
30
|
+
* text: 'Hello world',
|
|
31
|
+
* to: 'es',
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function Client(config: ClientConfig): ServiceClient {
|
|
36
|
+
const baseUrl = config.url || ''
|
|
37
|
+
const headers: Record<string, string> = {
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
...config.headers,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Add auth headers
|
|
43
|
+
if (config.auth) {
|
|
44
|
+
switch (config.auth.type) {
|
|
45
|
+
case 'api-key':
|
|
46
|
+
headers['Authorization'] = `Bearer ${config.auth.credentials.apiKey || config.auth.credentials.token}`
|
|
47
|
+
break
|
|
48
|
+
case 'basic':
|
|
49
|
+
const basicAuth = Buffer.from(
|
|
50
|
+
`${config.auth.credentials.username}:${config.auth.credentials.password}`
|
|
51
|
+
).toString('base64')
|
|
52
|
+
headers['Authorization'] = `Basic ${basicAuth}`
|
|
53
|
+
break
|
|
54
|
+
case 'jwt':
|
|
55
|
+
headers['Authorization'] = `Bearer ${config.auth.credentials.token}`
|
|
56
|
+
break
|
|
57
|
+
// OAuth would require more complex flow
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Make an HTTP request to the service
|
|
63
|
+
*/
|
|
64
|
+
async function request<T>(endpoint: string, body?: unknown): Promise<T> {
|
|
65
|
+
const url = `${baseUrl}/${endpoint.replace(/^\//, '')}`
|
|
66
|
+
const response = await fetch(url, {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers,
|
|
69
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
70
|
+
signal: config.timeout ? AbortSignal.timeout(config.timeout) : undefined,
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
throw new Error(`Service request failed: ${response.status} ${response.statusText}`)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return response.json() as Promise<T>
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
async ask(question: string, context?: unknown): Promise<string> {
|
|
82
|
+
const result = await request<{ answer: string }>('ask', { question, context })
|
|
83
|
+
return result.answer
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async deliver(orderId: string, results: unknown): Promise<void> {
|
|
87
|
+
await request('deliver', { orderId, results })
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
async do(action: string, input?: unknown): Promise<unknown> {
|
|
91
|
+
return request('do', { action, input })
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
async generate(prompt: string, options?: unknown): Promise<unknown> {
|
|
95
|
+
return request('generate', { prompt, options })
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
async is(value: unknown, type: string | JSONSchema): Promise<boolean> {
|
|
99
|
+
const result = await request<{ result: boolean }>('is', { value, type })
|
|
100
|
+
return result.result
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
async notify(notification: Notification): Promise<void> {
|
|
104
|
+
await request('notify', notification)
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
async order<TProduct>(product: TProduct, quantity: number): Promise<Order<TProduct>> {
|
|
108
|
+
return request('order', { product, quantity })
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
async quote<TProduct>(product: TProduct, quantity: number): Promise<Quote<TProduct>> {
|
|
112
|
+
return request('quote', { product, quantity })
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
async subscribe(planId: string): Promise<Subscription> {
|
|
116
|
+
return request('subscribe', { planId })
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
async entitlements(): Promise<string[]> {
|
|
120
|
+
const result = await request<{ entitlements: string[] }>('entitlements', {})
|
|
121
|
+
return result.entitlements
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
async kpis(): Promise<Record<string, number | string>> {
|
|
125
|
+
return request('kpis', {})
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
async okrs(): Promise<OKRDefinition[]> {
|
|
129
|
+
return request('okrs', {})
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
}
|
package/src/endpoint.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Endpoint helper for defining service endpoints
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { EndpointDefinition, PricingConfig, JSONSchema } from './types.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Endpoint configuration (input to Endpoint function)
|
|
9
|
+
*/
|
|
10
|
+
export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
|
|
11
|
+
/** Endpoint name */
|
|
12
|
+
name: string
|
|
13
|
+
/** Description of what this endpoint does */
|
|
14
|
+
description?: string
|
|
15
|
+
/** HTTP method (for REST endpoints) */
|
|
16
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
17
|
+
/** Path pattern (e.g., '/users/:id') */
|
|
18
|
+
path?: string
|
|
19
|
+
/** Input schema */
|
|
20
|
+
input?: JSONSchema
|
|
21
|
+
/** Output schema */
|
|
22
|
+
output?: JSONSchema
|
|
23
|
+
/** Handler function */
|
|
24
|
+
handler: EndpointDefinition<TInput, TOutput>['handler']
|
|
25
|
+
/** Pricing specific to this endpoint */
|
|
26
|
+
pricing?: PricingConfig
|
|
27
|
+
/** Rate limiting */
|
|
28
|
+
rateLimit?: {
|
|
29
|
+
requests: number
|
|
30
|
+
window: number // milliseconds
|
|
31
|
+
}
|
|
32
|
+
/** Whether authentication is required */
|
|
33
|
+
requiresAuth?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create an endpoint definition
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const translateEndpoint = Endpoint({
|
|
42
|
+
* name: 'translate',
|
|
43
|
+
* description: 'Translate text between languages',
|
|
44
|
+
* method: 'POST',
|
|
45
|
+
* path: '/translate',
|
|
46
|
+
* input: {
|
|
47
|
+
* type: 'object',
|
|
48
|
+
* properties: {
|
|
49
|
+
* text: { type: 'string', description: 'Text to translate' },
|
|
50
|
+
* from: { type: 'string', description: 'Source language code' },
|
|
51
|
+
* to: { type: 'string', description: 'Target language code' },
|
|
52
|
+
* },
|
|
53
|
+
* required: ['text', 'to'],
|
|
54
|
+
* additionalProperties: false,
|
|
55
|
+
* },
|
|
56
|
+
* output: {
|
|
57
|
+
* type: 'object',
|
|
58
|
+
* properties: {
|
|
59
|
+
* translatedText: { type: 'string' },
|
|
60
|
+
* confidence: { type: 'number' },
|
|
61
|
+
* },
|
|
62
|
+
* required: ['translatedText'],
|
|
63
|
+
* additionalProperties: false,
|
|
64
|
+
* },
|
|
65
|
+
* handler: async (input, context) => {
|
|
66
|
+
* // Translation logic here
|
|
67
|
+
* return {
|
|
68
|
+
* translatedText: `Translated: ${input.text}`,
|
|
69
|
+
* confidence: 0.95,
|
|
70
|
+
* }
|
|
71
|
+
* },
|
|
72
|
+
* pricing: {
|
|
73
|
+
* model: 'per-use',
|
|
74
|
+
* pricePerUnit: 0.01,
|
|
75
|
+
* currency: 'USD',
|
|
76
|
+
* },
|
|
77
|
+
* rateLimit: {
|
|
78
|
+
* requests: 100,
|
|
79
|
+
* window: 60000, // 1 minute
|
|
80
|
+
* },
|
|
81
|
+
* })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export function Endpoint<TInput = unknown, TOutput = unknown>(
|
|
85
|
+
config: EndpointConfig<TInput, TOutput>
|
|
86
|
+
): EndpointDefinition<TInput, TOutput> {
|
|
87
|
+
return {
|
|
88
|
+
name: config.name,
|
|
89
|
+
description: config.description,
|
|
90
|
+
method: config.method || 'POST',
|
|
91
|
+
path: config.path || `/${config.name}`,
|
|
92
|
+
input: config.input,
|
|
93
|
+
output: config.output,
|
|
94
|
+
handler: config.handler,
|
|
95
|
+
pricing: config.pricing,
|
|
96
|
+
rateLimit: config.rateLimit,
|
|
97
|
+
requiresAuth: config.requiresAuth !== false, // Default to true
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Create a GET endpoint
|
|
103
|
+
*/
|
|
104
|
+
export function GET<TInput = unknown, TOutput = unknown>(
|
|
105
|
+
config: Omit<EndpointConfig<TInput, TOutput>, 'method'>
|
|
106
|
+
): EndpointDefinition<TInput, TOutput> {
|
|
107
|
+
return Endpoint({ ...config, method: 'GET' })
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Create a POST endpoint
|
|
112
|
+
*/
|
|
113
|
+
export function POST<TInput = unknown, TOutput = unknown>(
|
|
114
|
+
config: Omit<EndpointConfig<TInput, TOutput>, 'method'>
|
|
115
|
+
): EndpointDefinition<TInput, TOutput> {
|
|
116
|
+
return Endpoint({ ...config, method: 'POST' })
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Create a PUT endpoint
|
|
121
|
+
*/
|
|
122
|
+
export function PUT<TInput = unknown, TOutput = unknown>(
|
|
123
|
+
config: Omit<EndpointConfig<TInput, TOutput>, 'method'>
|
|
124
|
+
): EndpointDefinition<TInput, TOutput> {
|
|
125
|
+
return Endpoint({ ...config, method: 'PUT' })
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Create a DELETE endpoint
|
|
130
|
+
*/
|
|
131
|
+
export function DELETE<TInput = unknown, TOutput = unknown>(
|
|
132
|
+
config: Omit<EndpointConfig<TInput, TOutput>, 'method'>
|
|
133
|
+
): EndpointDefinition<TInput, TOutput> {
|
|
134
|
+
return Endpoint({ ...config, method: 'DELETE' })
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Create a PATCH endpoint
|
|
139
|
+
*/
|
|
140
|
+
export function PATCH<TInput = unknown, TOutput = unknown>(
|
|
141
|
+
config: Omit<EndpointConfig<TInput, TOutput>, 'method'>
|
|
142
|
+
): EndpointDefinition<TInput, TOutput> {
|
|
143
|
+
return Endpoint({ ...config, method: 'PATCH' })
|
|
144
|
+
}
|