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
package/dist/index.js
CHANGED
|
@@ -1,172 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return pricing.outcomes.reduce((total, outcome) => {
|
|
20
|
-
const achievedValue = outcomes[outcome.metric] || 0;
|
|
21
|
-
if (achievedValue >= outcome.targetValue) {
|
|
22
|
-
return total + outcome.price;
|
|
23
|
-
}
|
|
24
|
-
return total;
|
|
25
|
-
}, 0);
|
|
26
|
-
}
|
|
27
|
-
function calculatePrice(pricing, params = {}) {
|
|
28
|
-
const { quantity = 1, activities = {}, outcomes = {} } = params;
|
|
29
|
-
switch (pricing.model) {
|
|
30
|
-
case "cost-based":
|
|
31
|
-
return calculateCostBasedPrice(pricing, quantity);
|
|
32
|
-
case "margin-based":
|
|
33
|
-
return calculateMarginBasedPrice(pricing, quantity);
|
|
34
|
-
case "activity-based":
|
|
35
|
-
return calculateActivityBasedPrice(pricing, activities);
|
|
36
|
-
case "outcome-based":
|
|
37
|
-
return calculateOutcomeBasedPrice(pricing, outcomes);
|
|
38
|
-
default:
|
|
39
|
-
throw new Error(`Unsupported pricing model: ${pricing.model}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// src/index.ts
|
|
44
|
-
function Service(definition) {
|
|
45
|
-
validateServiceDefinition(definition);
|
|
46
|
-
const service = {
|
|
47
|
-
...definition,
|
|
48
|
-
/**
|
|
49
|
-
* Calculate the price for this service
|
|
50
|
-
* @param params Parameters for price calculation
|
|
51
|
-
* @returns Calculated price
|
|
52
|
-
*/
|
|
53
|
-
calculatePrice(params) {
|
|
54
|
-
return calculatePrice(definition.pricing, params);
|
|
55
|
-
},
|
|
56
|
-
/**
|
|
57
|
-
* Register the service with the service registry
|
|
58
|
-
* @param options Optional configuration for service registration
|
|
59
|
-
* @returns Promise resolving to the registered service
|
|
60
|
-
*/
|
|
61
|
-
async register(options) {
|
|
62
|
-
try {
|
|
63
|
-
const { Services } = await import("services.do");
|
|
64
|
-
const services = new Services(options);
|
|
65
|
-
const serviceDefinition = {
|
|
66
|
-
name: definition.name,
|
|
67
|
-
description: definition.description,
|
|
68
|
-
endpoint: `https://api.services.do/implementations/${definition.implementation.type}/${definition.implementation.id}`,
|
|
69
|
-
version: definition.implementation.version,
|
|
70
|
-
metadata: {
|
|
71
|
-
...definition.metadata,
|
|
72
|
-
objective: definition.objective,
|
|
73
|
-
keyResults: definition.keyResults,
|
|
74
|
-
pricing: definition.pricing,
|
|
75
|
-
implementation: definition.implementation
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const registeredService = await services.register(serviceDefinition);
|
|
79
|
-
return {
|
|
80
|
-
...definition,
|
|
81
|
-
id: registeredService.id,
|
|
82
|
-
status: registeredService.status,
|
|
83
|
-
endpoint: registeredService.endpoint,
|
|
84
|
-
createdAt: registeredService.createdAt,
|
|
85
|
-
updatedAt: registeredService.updatedAt
|
|
86
|
-
};
|
|
87
|
-
} catch (error) {
|
|
88
|
-
console.warn("Failed to register with services.do, using mock implementation", error);
|
|
89
|
-
return {
|
|
90
|
-
...definition,
|
|
91
|
-
id: generateId(),
|
|
92
|
-
status: "active",
|
|
93
|
-
endpoint: `https://api.services.do/services/${generateId()}`,
|
|
94
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
95
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
/**
|
|
100
|
-
* Track progress towards key results
|
|
101
|
-
* @param results Record of key result updates
|
|
102
|
-
*/
|
|
103
|
-
trackProgress(results) {
|
|
104
|
-
definition.keyResults.forEach((kr) => {
|
|
105
|
-
if (kr.description in results) {
|
|
106
|
-
kr.currentValue = results[kr.description];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
/**
|
|
111
|
-
* Check if all key results have been achieved
|
|
112
|
-
* @returns Whether all key results have been achieved
|
|
113
|
-
*/
|
|
114
|
-
isObjectiveAchieved() {
|
|
115
|
-
return definition.keyResults.every((kr) => kr.currentValue !== void 0 && kr.target !== void 0 && kr.currentValue >= kr.target);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
return service;
|
|
119
|
-
}
|
|
120
|
-
function validateServiceDefinition(definition) {
|
|
121
|
-
const { name, objective, keyResults, pricing, implementation } = definition;
|
|
122
|
-
if (!name) {
|
|
123
|
-
throw new Error("Service name is required");
|
|
124
|
-
}
|
|
125
|
-
if (!objective || !objective.description) {
|
|
126
|
-
throw new Error("Service objective with description is required");
|
|
127
|
-
}
|
|
128
|
-
if (!keyResults || !Array.isArray(keyResults) || keyResults.length === 0) {
|
|
129
|
-
throw new Error("At least one key result is required");
|
|
130
|
-
}
|
|
131
|
-
if (!pricing || !pricing.model) {
|
|
132
|
-
throw new Error("Service pricing model is required");
|
|
133
|
-
}
|
|
134
|
-
if (!implementation || !implementation.type || !implementation.id) {
|
|
135
|
-
throw new Error("Service implementation details are required");
|
|
136
|
-
}
|
|
137
|
-
switch (pricing.model) {
|
|
138
|
-
case "cost-based":
|
|
139
|
-
if (pricing.costBase === void 0) {
|
|
140
|
-
throw new Error("Cost base is required for cost-based pricing");
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
case "margin-based":
|
|
144
|
-
if (pricing.costBase === void 0 || pricing.marginPercentage === void 0) {
|
|
145
|
-
throw new Error("Cost base and margin percentage are required for margin-based pricing");
|
|
146
|
-
}
|
|
147
|
-
break;
|
|
148
|
-
case "activity-based":
|
|
149
|
-
if (!pricing.activities || !Array.isArray(pricing.activities) || pricing.activities.length === 0) {
|
|
150
|
-
throw new Error("At least one activity is required for activity-based pricing");
|
|
151
|
-
}
|
|
152
|
-
break;
|
|
153
|
-
case "outcome-based":
|
|
154
|
-
if (!pricing.outcomes || !Array.isArray(pricing.outcomes) || pricing.outcomes.length === 0) {
|
|
155
|
-
throw new Error("At least one outcome is required for outcome-based pricing");
|
|
156
|
-
}
|
|
157
|
-
break;
|
|
158
|
-
default:
|
|
159
|
-
throw new Error(`Unsupported pricing model: ${pricing.model}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function generateId() {
|
|
163
|
-
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
164
|
-
}
|
|
165
|
-
export {
|
|
166
|
-
Service,
|
|
167
|
-
calculateActivityBasedPrice,
|
|
168
|
-
calculateCostBasedPrice,
|
|
169
|
-
calculateMarginBasedPrice,
|
|
170
|
-
calculateOutcomeBasedPrice,
|
|
171
|
-
calculatePrice
|
|
172
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* services-as-software - Primitives for building AI-powered services that operate as software
|
|
3
|
+
*
|
|
4
|
+
* Services are a superset of digital-workers with a payment/business overlay,
|
|
5
|
+
* capable of crossing company/business boundaries.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
// Export entity definitions (Nouns)
|
|
10
|
+
export * from './entities/index.js';
|
|
11
|
+
// Core service primitives
|
|
12
|
+
export { Service } from './service.js';
|
|
13
|
+
export { Endpoint, GET, POST, PUT, DELETE, PATCH } from './endpoint.js';
|
|
14
|
+
export { Client } from './client.js';
|
|
15
|
+
export { Provider, providers } from './provider.js';
|
|
16
|
+
// Helper functions for common operations
|
|
17
|
+
export { ask, deliver, do_ as do, generate, is, notify, on, order, queue, quote, subscribe, every, entitlements, kpis, okrs, Plan, KPI, OKR, Entitlement, } from './helpers.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oCAAoC;AACpC,cAAc,qBAAqB,CAAA;AAEnC,0BAA0B;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEnD,yCAAyC;AACzC,OAAO,EACL,GAAG,EACH,OAAO,EACP,GAAG,IAAI,EAAE,EACT,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,GAAG,EACH,WAAW,GACZ,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service provider for managing multiple services
|
|
3
|
+
*/
|
|
4
|
+
import type { Provider, ClientConfig } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Provider configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface ProviderConfig {
|
|
9
|
+
/** Provider name */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Base URL for all services */
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
/** Authentication configuration */
|
|
14
|
+
auth?: ClientConfig['auth'];
|
|
15
|
+
/** Available services */
|
|
16
|
+
services?: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create a service provider
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const provider = Provider({
|
|
24
|
+
* name: 'AWS',
|
|
25
|
+
* baseUrl: 'https://api.aws.amazon.com',
|
|
26
|
+
* auth: {
|
|
27
|
+
* type: 'api-key',
|
|
28
|
+
* credentials: { apiKey: process.env.AWS_API_KEY },
|
|
29
|
+
* },
|
|
30
|
+
* services: ['translate', 'comprehend', 'polly'],
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* // Get a service client
|
|
34
|
+
* const translate = provider.service('translate')
|
|
35
|
+
* const result = await translate.do('translate', {
|
|
36
|
+
* text: 'Hello',
|
|
37
|
+
* to: 'es',
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function Provider(config: ProviderConfig): Provider;
|
|
42
|
+
/**
|
|
43
|
+
* Common cloud providers
|
|
44
|
+
*/
|
|
45
|
+
export declare const providers: {
|
|
46
|
+
/**
|
|
47
|
+
* AWS provider
|
|
48
|
+
*/
|
|
49
|
+
aws(credentials: {
|
|
50
|
+
accessKeyId: string;
|
|
51
|
+
secretAccessKey: string;
|
|
52
|
+
region?: string;
|
|
53
|
+
}): Provider;
|
|
54
|
+
/**
|
|
55
|
+
* Google Cloud provider
|
|
56
|
+
*/
|
|
57
|
+
gcp(credentials: {
|
|
58
|
+
apiKey: string;
|
|
59
|
+
projectId?: string;
|
|
60
|
+
}): Provider;
|
|
61
|
+
/**
|
|
62
|
+
* Azure provider
|
|
63
|
+
*/
|
|
64
|
+
azure(credentials: {
|
|
65
|
+
subscriptionKey: string;
|
|
66
|
+
region?: string;
|
|
67
|
+
}): Provider;
|
|
68
|
+
/**
|
|
69
|
+
* OpenAI provider
|
|
70
|
+
*/
|
|
71
|
+
openai(credentials: {
|
|
72
|
+
apiKey: string;
|
|
73
|
+
}): Provider;
|
|
74
|
+
/**
|
|
75
|
+
* Anthropic provider
|
|
76
|
+
*/
|
|
77
|
+
anthropic(credentials: {
|
|
78
|
+
apiKey: string;
|
|
79
|
+
}): Provider;
|
|
80
|
+
/**
|
|
81
|
+
* Custom provider
|
|
82
|
+
*/
|
|
83
|
+
custom(config: ProviderConfig): Provider;
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAiB,YAAY,EAAE,MAAM,YAAY,CAAA;AAGvE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,mCAAmC;IACnC,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;IAC3B,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CAoBzD;AAED;;GAEG;AACH,eAAO,MAAM,SAAS;IACpB;;OAEG;qBACc;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ;IAsB7F;;OAEG;qBACc;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ;IAkBlE;;OAEG;uBACgB;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ;IAkB1E;;OAEG;wBACiB;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ;IAkBjD;;OAEG;2BACoB;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ;IAepD;;OAEG;mBACY,cAAc,GAAG,QAAQ;CAGzC,CAAA"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service provider for managing multiple services
|
|
3
|
+
*/
|
|
4
|
+
import { Client } from './client.js';
|
|
5
|
+
/**
|
|
6
|
+
* Create a service provider
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const provider = Provider({
|
|
11
|
+
* name: 'AWS',
|
|
12
|
+
* baseUrl: 'https://api.aws.amazon.com',
|
|
13
|
+
* auth: {
|
|
14
|
+
* type: 'api-key',
|
|
15
|
+
* credentials: { apiKey: process.env.AWS_API_KEY },
|
|
16
|
+
* },
|
|
17
|
+
* services: ['translate', 'comprehend', 'polly'],
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* // Get a service client
|
|
21
|
+
* const translate = provider.service('translate')
|
|
22
|
+
* const result = await translate.do('translate', {
|
|
23
|
+
* text: 'Hello',
|
|
24
|
+
* to: 'es',
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function Provider(config) {
|
|
29
|
+
return {
|
|
30
|
+
name: config.name,
|
|
31
|
+
baseUrl: config.baseUrl,
|
|
32
|
+
auth: config.auth,
|
|
33
|
+
services: config.services || [],
|
|
34
|
+
service(serviceName) {
|
|
35
|
+
// Construct service URL
|
|
36
|
+
const serviceUrl = `${config.baseUrl}/${serviceName}`;
|
|
37
|
+
// Create a client for this service
|
|
38
|
+
const client = Client({
|
|
39
|
+
url: serviceUrl,
|
|
40
|
+
auth: config.auth,
|
|
41
|
+
});
|
|
42
|
+
return client;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Common cloud providers
|
|
48
|
+
*/
|
|
49
|
+
export const providers = {
|
|
50
|
+
/**
|
|
51
|
+
* AWS provider
|
|
52
|
+
*/
|
|
53
|
+
aws(credentials) {
|
|
54
|
+
return Provider({
|
|
55
|
+
name: 'AWS',
|
|
56
|
+
baseUrl: `https://api.${credentials.region || 'us-east-1'}.amazonaws.com`,
|
|
57
|
+
auth: {
|
|
58
|
+
type: 'api-key',
|
|
59
|
+
credentials: {
|
|
60
|
+
apiKey: credentials.accessKeyId,
|
|
61
|
+
secret: credentials.secretAccessKey,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
services: [
|
|
65
|
+
'translate',
|
|
66
|
+
'comprehend',
|
|
67
|
+
'polly',
|
|
68
|
+
'rekognition',
|
|
69
|
+
'textract',
|
|
70
|
+
'transcribe',
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Google Cloud provider
|
|
76
|
+
*/
|
|
77
|
+
gcp(credentials) {
|
|
78
|
+
return Provider({
|
|
79
|
+
name: 'Google Cloud',
|
|
80
|
+
baseUrl: 'https://api.googleapis.com',
|
|
81
|
+
auth: {
|
|
82
|
+
type: 'api-key',
|
|
83
|
+
credentials: { apiKey: credentials.apiKey },
|
|
84
|
+
},
|
|
85
|
+
services: [
|
|
86
|
+
'translate',
|
|
87
|
+
'language',
|
|
88
|
+
'speech',
|
|
89
|
+
'texttospeech',
|
|
90
|
+
'vision',
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* Azure provider
|
|
96
|
+
*/
|
|
97
|
+
azure(credentials) {
|
|
98
|
+
return Provider({
|
|
99
|
+
name: 'Azure',
|
|
100
|
+
baseUrl: `https://${credentials.region || 'eastus'}.api.cognitive.microsoft.com`,
|
|
101
|
+
auth: {
|
|
102
|
+
type: 'api-key',
|
|
103
|
+
credentials: { apiKey: credentials.subscriptionKey },
|
|
104
|
+
},
|
|
105
|
+
services: [
|
|
106
|
+
'translator',
|
|
107
|
+
'language',
|
|
108
|
+
'speech',
|
|
109
|
+
'vision',
|
|
110
|
+
'form-recognizer',
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
/**
|
|
115
|
+
* OpenAI provider
|
|
116
|
+
*/
|
|
117
|
+
openai(credentials) {
|
|
118
|
+
return Provider({
|
|
119
|
+
name: 'OpenAI',
|
|
120
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
121
|
+
auth: {
|
|
122
|
+
type: 'api-key',
|
|
123
|
+
credentials: { apiKey: credentials.apiKey },
|
|
124
|
+
},
|
|
125
|
+
services: [
|
|
126
|
+
'chat',
|
|
127
|
+
'completions',
|
|
128
|
+
'embeddings',
|
|
129
|
+
'images',
|
|
130
|
+
'audio',
|
|
131
|
+
],
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
/**
|
|
135
|
+
* Anthropic provider
|
|
136
|
+
*/
|
|
137
|
+
anthropic(credentials) {
|
|
138
|
+
return Provider({
|
|
139
|
+
name: 'Anthropic',
|
|
140
|
+
baseUrl: 'https://api.anthropic.com/v1',
|
|
141
|
+
auth: {
|
|
142
|
+
type: 'api-key',
|
|
143
|
+
credentials: { apiKey: credentials.apiKey },
|
|
144
|
+
},
|
|
145
|
+
services: [
|
|
146
|
+
'messages',
|
|
147
|
+
'completions',
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Custom provider
|
|
153
|
+
*/
|
|
154
|
+
custom(config) {
|
|
155
|
+
return Provider(config);
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service implementation
|
|
3
|
+
*/
|
|
4
|
+
import type { ServiceDefinition, Service } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Create a service from a definition
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const service = Service({
|
|
11
|
+
* name: 'translation-service',
|
|
12
|
+
* version: '1.0.0',
|
|
13
|
+
* description: 'AI-powered translation service',
|
|
14
|
+
* pricing: {
|
|
15
|
+
* model: 'per-use',
|
|
16
|
+
* pricePerUnit: 0.01,
|
|
17
|
+
* currency: 'USD',
|
|
18
|
+
* },
|
|
19
|
+
* endpoints: [
|
|
20
|
+
* Endpoint({
|
|
21
|
+
* name: 'translate',
|
|
22
|
+
* method: 'POST',
|
|
23
|
+
* path: '/translate',
|
|
24
|
+
* input: {
|
|
25
|
+
* type: 'object',
|
|
26
|
+
* properties: {
|
|
27
|
+
* text: { type: 'string' },
|
|
28
|
+
* from: { type: 'string' },
|
|
29
|
+
* to: { type: 'string' },
|
|
30
|
+
* },
|
|
31
|
+
* required: ['text', 'to'],
|
|
32
|
+
* },
|
|
33
|
+
* handler: async (input) => {
|
|
34
|
+
* // Translation logic here
|
|
35
|
+
* return { translatedText: input.text }
|
|
36
|
+
* },
|
|
37
|
+
* }),
|
|
38
|
+
* ],
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function Service(definition: ServiceDefinition): Service;
|
|
43
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,OAAO,EAWR,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,OAAO,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CA0M9D"}
|