@applica-software-guru/persona-sdk 0.1.100 → 0.1.101

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 (170) hide show
  1. package/.eslintrc.cjs +6 -5
  2. package/.nvmrc +1 -1
  3. package/.prettierignore +3 -5
  4. package/.prettierrc +3 -5
  5. package/README.md +360 -20
  6. package/bitbucket-pipelines.yml +6 -5
  7. package/dist/bundle.cjs.js +1 -27
  8. package/dist/bundle.cjs.js.map +1 -1
  9. package/dist/bundle.es.js +700 -5086
  10. package/dist/bundle.es.js.map +1 -1
  11. package/dist/index.d.ts +1442 -8
  12. package/package.json +9 -51
  13. package/src/agents/agents-api.ts +66 -0
  14. package/src/agents/types.ts +349 -0
  15. package/src/auth/api-key-auth.ts +13 -0
  16. package/src/auth/authentication-provider.ts +4 -0
  17. package/src/auth/bearer-token-auth.ts +13 -0
  18. package/src/auth/index.ts +3 -0
  19. package/src/billing/billing-client.ts +182 -0
  20. package/src/billing/types.ts +166 -0
  21. package/src/credentials/credentials-api.ts +40 -0
  22. package/src/credentials/types.ts +67 -0
  23. package/src/exceptions.ts +10 -0
  24. package/src/features/feature-templates-api.ts +43 -0
  25. package/src/features/features-api.ts +16 -0
  26. package/src/features/types.ts +25 -0
  27. package/src/http-api.ts +102 -0
  28. package/src/index.ts +179 -7
  29. package/src/knowledges/knowledge-base-documents-api.ts +39 -0
  30. package/src/knowledges/knowledge-bases-api.ts +48 -0
  31. package/src/knowledges/types.ts +70 -0
  32. package/src/known-models/known-models-api.ts +33 -0
  33. package/src/known-models/types.ts +7 -0
  34. package/src/missions/missions-api.ts +62 -0
  35. package/src/missions/types.ts +25 -0
  36. package/src/paginated.ts +6 -0
  37. package/src/persona-sdk.ts +104 -0
  38. package/src/projects/projects-api.ts +90 -0
  39. package/src/projects/types.ts +52 -0
  40. package/src/revisions/types.ts +9 -0
  41. package/src/service-prices/service-prices-api.ts +33 -0
  42. package/src/service-prices/types.ts +8 -0
  43. package/src/sessions/sessions-api.ts +90 -0
  44. package/src/sessions/types.ts +150 -0
  45. package/src/triggers/trigger-executions-api.ts +28 -0
  46. package/src/triggers/triggers-api.ts +38 -0
  47. package/src/triggers/types.ts +50 -0
  48. package/src/values/values-api.ts +84 -0
  49. package/src/workflows/types.ts +150 -0
  50. package/src/workflows/workflow-executions-api.ts +28 -0
  51. package/src/workflows/workflows-api.ts +52 -0
  52. package/tsconfig.json +20 -28
  53. package/vite.config.ts +20 -67
  54. package/.github/copilot-instructions.md +0 -3
  55. package/CLAUDE.md +0 -3
  56. package/GEMINI.md +0 -3
  57. package/components.json +0 -24
  58. package/dist/bundle.iife.js +0 -28
  59. package/dist/bundle.iife.js.map +0 -1
  60. package/dist/bundle.umd.js +0 -28
  61. package/dist/bundle.umd.js.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/logging.d.ts +0 -18
  64. package/dist/logging.d.ts.map +0 -1
  65. package/dist/messages.d.ts +0 -9
  66. package/dist/messages.d.ts.map +0 -1
  67. package/dist/projects.d.ts +0 -17
  68. package/dist/projects.d.ts.map +0 -1
  69. package/dist/protocol/base.d.ts +0 -25
  70. package/dist/protocol/base.d.ts.map +0 -1
  71. package/dist/protocol/index.d.ts +0 -6
  72. package/dist/protocol/index.d.ts.map +0 -1
  73. package/dist/protocol/rest.d.ts +0 -25
  74. package/dist/protocol/rest.d.ts.map +0 -1
  75. package/dist/protocol/transaction.d.ts +0 -56
  76. package/dist/protocol/transaction.d.ts.map +0 -1
  77. package/dist/protocol/webrtc.d.ts +0 -60
  78. package/dist/protocol/webrtc.d.ts.map +0 -1
  79. package/dist/protocol/websocket.d.ts +0 -22
  80. package/dist/protocol/websocket.d.ts.map +0 -1
  81. package/dist/runtime/context.d.ts +0 -34
  82. package/dist/runtime/context.d.ts.map +0 -1
  83. package/dist/runtime/file-attachment-adapter.d.ts +0 -15
  84. package/dist/runtime/file-attachment-adapter.d.ts.map +0 -1
  85. package/dist/runtime/handlers.d.ts +0 -21
  86. package/dist/runtime/handlers.d.ts.map +0 -1
  87. package/dist/runtime/listeners.d.ts +0 -6
  88. package/dist/runtime/listeners.d.ts.map +0 -1
  89. package/dist/runtime/protocols.d.ts +0 -17
  90. package/dist/runtime/protocols.d.ts.map +0 -1
  91. package/dist/runtime/threads.d.ts +0 -34
  92. package/dist/runtime/threads.d.ts.map +0 -1
  93. package/dist/runtime/utils.d.ts +0 -10
  94. package/dist/runtime/utils.d.ts.map +0 -1
  95. package/dist/runtime.d.ts +0 -6
  96. package/dist/runtime.d.ts.map +0 -1
  97. package/dist/storage/base.d.ts +0 -9
  98. package/dist/storage/base.d.ts.map +0 -1
  99. package/dist/storage/index.d.ts +0 -3
  100. package/dist/storage/index.d.ts.map +0 -1
  101. package/dist/storage/persona.d.ts +0 -29
  102. package/dist/storage/persona.d.ts.map +0 -1
  103. package/dist/tools.d.ts +0 -72
  104. package/dist/tools.d.ts.map +0 -1
  105. package/dist/types.d.ts +0 -237
  106. package/dist/types.d.ts.map +0 -1
  107. package/docs/README.md +0 -13
  108. package/docs/api-reference.md +0 -16
  109. package/docs/contributing.md +0 -21
  110. package/docs/customization.md +0 -74
  111. package/docs/features.md +0 -7
  112. package/docs/installation.md +0 -9
  113. package/docs/messages.md +0 -214
  114. package/docs/protocols.md +0 -39
  115. package/docs/transactions.md +0 -121
  116. package/docs/usage.md +0 -40
  117. package/jsconfig.node.json +0 -10
  118. package/playground/index.html +0 -14
  119. package/playground/src/app.tsx +0 -10
  120. package/playground/src/chat.tsx +0 -117
  121. package/playground/src/components/assistant-ui/assistant-modal.tsx +0 -57
  122. package/playground/src/components/assistant-ui/attachment.tsx +0 -197
  123. package/playground/src/components/assistant-ui/markdown-text.tsx +0 -228
  124. package/playground/src/components/assistant-ui/thread-list.tsx +0 -91
  125. package/playground/src/components/assistant-ui/thread.tsx +0 -302
  126. package/playground/src/components/assistant-ui/threadlist-sidebar.tsx +0 -59
  127. package/playground/src/components/assistant-ui/tool-fallback.tsx +0 -93
  128. package/playground/src/components/assistant-ui/tooltip-icon-button.tsx +0 -42
  129. package/playground/src/components/chat/logging.tsx +0 -53
  130. package/playground/src/components/ui/avatar.tsx +0 -51
  131. package/playground/src/components/ui/button.tsx +0 -60
  132. package/playground/src/components/ui/dialog.tsx +0 -141
  133. package/playground/src/components/ui/input.tsx +0 -21
  134. package/playground/src/components/ui/separator.tsx +0 -26
  135. package/playground/src/components/ui/sheet.tsx +0 -139
  136. package/playground/src/components/ui/sidebar.tsx +0 -619
  137. package/playground/src/components/ui/skeleton.tsx +0 -13
  138. package/playground/src/components/ui/tooltip.tsx +0 -59
  139. package/playground/src/hooks/theme.ts +0 -70
  140. package/playground/src/hooks/use-mobile.ts +0 -19
  141. package/playground/src/lib/utils.ts +0 -6
  142. package/playground/src/main.tsx +0 -10
  143. package/playground/src/styles.css +0 -120
  144. package/playground/src/tools.ts +0 -149
  145. package/playground/src/vite-env.d.ts +0 -1
  146. package/preview-build.sh +0 -23
  147. package/src/logging.ts +0 -34
  148. package/src/messages.ts +0 -202
  149. package/src/projects.ts +0 -57
  150. package/src/protocol/base.ts +0 -73
  151. package/src/protocol/index.ts +0 -5
  152. package/src/protocol/rest.ts +0 -107
  153. package/src/protocol/transaction.ts +0 -182
  154. package/src/protocol/webrtc.ts +0 -379
  155. package/src/protocol/websocket.ts +0 -111
  156. package/src/runtime/context.ts +0 -88
  157. package/src/runtime/file-attachment-adapter.ts +0 -48
  158. package/src/runtime/handlers.ts +0 -322
  159. package/src/runtime/index.ts +0 -6
  160. package/src/runtime/listeners.ts +0 -79
  161. package/src/runtime/protocols.ts +0 -169
  162. package/src/runtime/threads.ts +0 -105
  163. package/src/runtime/utils.ts +0 -46
  164. package/src/runtime.tsx +0 -334
  165. package/src/storage/base.ts +0 -13
  166. package/src/storage/index.ts +0 -2
  167. package/src/storage/persona.ts +0 -138
  168. package/src/tools.ts +0 -211
  169. package/src/types.ts +0 -284
  170. package/tsconfig.node.json +0 -15
@@ -0,0 +1,182 @@
1
+ import { AuthenticationProvider } from '../auth/authentication-provider';
2
+ import { ApiException } from '../exceptions';
3
+ import {
4
+ Customer,
5
+ Subscription,
6
+ Invoice,
7
+ CreateCustomerRequest,
8
+ UpdateCustomerRequest,
9
+ CreateSubscriptionRequest,
10
+ UpgradeSubscriptionRequest,
11
+ DowngradeSubscriptionRequest,
12
+ MentorizeSubscriptionRequest,
13
+ UsageStats,
14
+ UsagePage,
15
+ } from './types';
16
+
17
+ export class BillingClient {
18
+ private readonly baseUrl: string;
19
+ private readonly authProvider: AuthenticationProvider | string | null;
20
+
21
+ constructor(baseUrl?: string, auth?: string | AuthenticationProvider | null) {
22
+ this.baseUrl = (baseUrl || 'https://persona.applica.guru/billing').replace(/\/$/, '');
23
+ this.authProvider = auth ?? null;
24
+ }
25
+
26
+ private buildHeaders(): Headers {
27
+ const headers = new Headers();
28
+ headers.set('Content-Type', 'application/json');
29
+ if (this.authProvider) {
30
+ if (typeof this.authProvider === 'string') {
31
+ headers.set('x-persona-apikey', this.authProvider);
32
+ } else {
33
+ this.authProvider.applyHeaders(headers);
34
+ }
35
+ }
36
+ return headers;
37
+ }
38
+
39
+ private async request<T>(path: string, method: string, body?: unknown): Promise<T> {
40
+ const response = await fetch(this.baseUrl + path, {
41
+ method,
42
+ headers: this.buildHeaders(),
43
+ body: body ? JSON.stringify(body) : undefined,
44
+ });
45
+ if (!response.ok) {
46
+ const text = await response.text();
47
+ throw new ApiException(response.status, text);
48
+ }
49
+ const text = await response.text();
50
+ return text ? JSON.parse(text) : (undefined as T);
51
+ }
52
+
53
+ async createCustomer(request: CreateCustomerRequest): Promise<Customer> {
54
+ return this.request<Customer>('/customers', 'POST', request);
55
+ }
56
+
57
+ async updateCustomer(owner: string, request: UpdateCustomerRequest): Promise<Customer> {
58
+ return this.request<Customer>('/customers/' + owner, 'PUT', request);
59
+ }
60
+
61
+ async getCustomer(owner: string): Promise<Customer> {
62
+ return this.request<Customer>('/customers/' + owner, 'GET');
63
+ }
64
+
65
+ async saveCustomer(customer: Customer): Promise<Customer> {
66
+ return this.request<Customer>('/customers', 'POST', customer);
67
+ }
68
+
69
+ async deleteCustomer(owner: string): Promise<void> {
70
+ await this.request<void>('/customers/' + owner, 'DELETE');
71
+ }
72
+
73
+ async createSubscription(request: CreateSubscriptionRequest): Promise<Subscription> {
74
+ return this.request<Subscription>('/customers/' + request.owner + '/subscription', 'POST', request);
75
+ }
76
+
77
+ async getSubscription(owner: string): Promise<Subscription> {
78
+ return this.request<Subscription>('/customers/' + owner + '/subscription', 'GET');
79
+ }
80
+
81
+ async getProjectSubscription(projectId: string): Promise<Subscription> {
82
+ return this.request<Subscription>('/projects/' + projectId + '/subscription', 'GET');
83
+ }
84
+
85
+ async changeProjectSubscriptionPlan(projectId: string, request: { toPlanType: string }): Promise<Subscription> {
86
+ return this.request<Subscription>('/projects/' + projectId + '/subscription/actions/change-plan', 'POST', request);
87
+ }
88
+
89
+ async addProjectSubscriptionCredits(projectId: string, request: { credits: number }): Promise<Subscription> {
90
+ return this.request<Subscription>('/projects/' + projectId + '/subscription/actions/add-credits', 'POST', request);
91
+ }
92
+
93
+ async beginUpgrade(owner: string, request: UpgradeSubscriptionRequest): Promise<Subscription> {
94
+ return this.request<Subscription>('/customers/' + owner + '/subscription/actions/upgrade', 'POST', request);
95
+ }
96
+
97
+ async downgrade(owner: string, request: DowngradeSubscriptionRequest): Promise<Subscription> {
98
+ return this.request<Subscription>('/customers/' + owner + '/subscription/actions/downgrade', 'POST', request);
99
+ }
100
+
101
+ async mentorize(owner: string, request: MentorizeSubscriptionRequest): Promise<Subscription> {
102
+ return this.request<Subscription>('/customers/' + owner + '/subscription/actions/mentorize', 'POST', request);
103
+ }
104
+
105
+ async addCredits(owner: string, credits: number): Promise<Subscription> {
106
+ return this.request<Subscription>('/customers/' + owner + '/subscription/credits', 'POST', { credits });
107
+ }
108
+
109
+ async useCredits(
110
+ owner: string,
111
+ credits: number,
112
+ services: string[],
113
+ referenceId?: string,
114
+ totalCost?: number,
115
+ totalPrice?: number,
116
+ ): Promise<Subscription> {
117
+ const body: Record<string, unknown> = { credits, services };
118
+ if (referenceId) body.referenceId = referenceId;
119
+ if (totalCost !== undefined) body.totalCost = totalCost;
120
+ if (totalPrice !== undefined) body.totalPrice = totalPrice;
121
+ return this.request<Subscription>('/customers/' + owner + '/subscription/credits', 'DELETE', body);
122
+ }
123
+
124
+ async getCredits(owner: string): Promise<number> {
125
+ try {
126
+ const result = await this.request<{ credits?: number }>('/customers/' + owner + '/subscription/credits', 'GET');
127
+ return result.credits ?? 0;
128
+ } catch {
129
+ return 0;
130
+ }
131
+ }
132
+
133
+ async isValid(owner: string): Promise<boolean> {
134
+ try {
135
+ const result = await this.request<{ valid?: boolean }>('/customers/' + owner + '/subscription/valid', 'GET');
136
+ return result.valid ?? false;
137
+ } catch {
138
+ return false;
139
+ }
140
+ }
141
+
142
+ async listInvoices(owner: string, dateFrom?: string, dateTo?: string): Promise<Invoice[]> {
143
+ const params: string[] = [];
144
+ if (dateFrom) params.push('date_from=' + dateFrom);
145
+ if (dateTo) params.push('date_to=' + dateTo);
146
+ const query = params.length > 0 ? '?' + params.join('&') : '';
147
+ return this.request<Invoice[]>('/customers/' + owner + '/invoices' + query, 'GET');
148
+ }
149
+
150
+ async cancelSubscription(owner: string): Promise<Subscription> {
151
+ return this.request<Subscription>('/customers/' + owner + '/subscription/actions/cancel', 'POST', {});
152
+ }
153
+
154
+ async getUsageStats(projectId: string, dateFrom?: string, dateTo?: string, models?: string[]): Promise<UsageStats> {
155
+ const params: string[] = [];
156
+ if (dateFrom) params.push('date_from=' + encodeURIComponent(dateFrom));
157
+ if (dateTo) params.push('date_to=' + encodeURIComponent(dateTo));
158
+ if (models?.length) models.forEach(m => params.push('model=' + encodeURIComponent(m)));
159
+ const query = params.length > 0 ? '?' + params.join('&') : '';
160
+ return this.request<UsageStats>('/projects/' + projectId + '/subscription/usage-stats' + query, 'GET');
161
+ }
162
+
163
+ async listUsages(
164
+ projectId: string,
165
+ dateFrom?: string,
166
+ dateTo?: string,
167
+ models?: string[],
168
+ sessionId?: string,
169
+ page?: number,
170
+ size?: number,
171
+ ): Promise<UsagePage> {
172
+ const params: string[] = [];
173
+ if (dateFrom) params.push('date_from=' + encodeURIComponent(dateFrom));
174
+ if (dateTo) params.push('date_to=' + encodeURIComponent(dateTo));
175
+ if (models?.length) models.forEach(m => params.push('model=' + encodeURIComponent(m)));
176
+ if (sessionId) params.push('session_id=' + encodeURIComponent(sessionId));
177
+ if (page !== undefined) params.push('page=' + encodeURIComponent(String(page)));
178
+ if (size !== undefined) params.push('size=' + encodeURIComponent(String(size)));
179
+ const query = params.length > 0 ? '?' + params.join('&') : '';
180
+ return this.request<UsagePage>('/projects/' + projectId + '/subscription/usages' + query, 'GET');
181
+ }
182
+ }
@@ -0,0 +1,166 @@
1
+ export interface Customer {
2
+ id?: string;
3
+ owner?: string;
4
+ name?: string;
5
+ email?: string;
6
+ phone?: string;
7
+ address?: string;
8
+ stripeCustomerId?: string;
9
+ }
10
+
11
+ export interface Subscription {
12
+ id?: string;
13
+ projectId?: string;
14
+ owner?: string;
15
+ planType?: string;
16
+ status?: string;
17
+ startDate?: string;
18
+ planCredits?: number;
19
+ extraCredits?: number;
20
+ keepCreditsOnRenew?: boolean;
21
+ endDate?: string;
22
+ createdAt?: string;
23
+ updatedAt?: string;
24
+ stripeCustomerId?: string;
25
+ stripeSubscriptionId?: string;
26
+ }
27
+
28
+ export interface Invoice {
29
+ id?: string;
30
+ subscriptionId?: string;
31
+ status?: string;
32
+ amountDue?: number;
33
+ amountPaid?: number;
34
+ currency?: string;
35
+ customerEmail?: string;
36
+ customerName?: string;
37
+ hostedInvoiceUrl?: string;
38
+ invoicePdf?: string;
39
+ dueDate?: string;
40
+ createdAt?: string;
41
+ updatedAt?: string;
42
+ lines?: LineItem[];
43
+ }
44
+
45
+ export interface LineItem {
46
+ description?: string;
47
+ amount?: number;
48
+ currency?: string;
49
+ quantity?: number;
50
+ periodStart?: string;
51
+ periodEnd?: string;
52
+ }
53
+
54
+ export interface Usage {
55
+ id?: string;
56
+ subscriptionId?: string;
57
+ creditsUsed?: number;
58
+ services?: string[];
59
+ totalCost?: number;
60
+ totalPrice?: number;
61
+ referenceId?: string;
62
+ sessionId?: string;
63
+ userId?: string;
64
+ details?: UsageDetail[];
65
+ createdAt?: string;
66
+ }
67
+
68
+ export interface UsageDetail {
69
+ service?: string;
70
+ value?: number;
71
+ cost?: number;
72
+ price?: number;
73
+ credits?: number;
74
+ unit?: string;
75
+ [key: string]: unknown;
76
+ }
77
+
78
+ export interface UsagePage {
79
+ content: Usage[];
80
+ totalElements: number;
81
+ totalPages: number;
82
+ page: number;
83
+ size: number;
84
+ }
85
+
86
+ export interface Payment {
87
+ id?: string;
88
+ subscriptionId?: string;
89
+ status?: string;
90
+ product?: string;
91
+ quantity?: number;
92
+ createdAt?: string;
93
+ updatedAt?: string;
94
+ checkoutUrl?: string;
95
+ stripeCheckoutSessionId?: string;
96
+ stripeCustomerId?: string;
97
+ stripeSubscriptionId?: string;
98
+ }
99
+
100
+ export interface CreateCustomerRequest {
101
+ owner?: string;
102
+ name?: string;
103
+ email?: string;
104
+ phone?: string;
105
+ }
106
+
107
+ export interface UpdateCustomerRequest {
108
+ name?: string;
109
+ email?: string;
110
+ phone?: string;
111
+ }
112
+
113
+ export interface CreateSubscriptionRequest {
114
+ owner: string;
115
+ }
116
+
117
+ export interface UpgradeSubscriptionRequest {
118
+ toPlanType: string;
119
+ }
120
+
121
+ export interface DowngradeSubscriptionRequest {
122
+ toPlanType: string;
123
+ }
124
+
125
+ export interface MentorizeSubscriptionRequest {
126
+ endDate?: string;
127
+ }
128
+
129
+ export interface UsageDailyEntry {
130
+ date: string;
131
+ credits: number;
132
+ count: number;
133
+ totalCost?: number;
134
+ totalPrice?: number;
135
+ }
136
+
137
+ export interface UsageModelEntry {
138
+ model: string;
139
+ credits: number;
140
+ count: number;
141
+ totalCost?: number;
142
+ totalPrice?: number;
143
+ }
144
+
145
+ export interface UsageTotals {
146
+ creditsUsed: number;
147
+ usageCount: number;
148
+ previousCreditsUsed: number;
149
+ totalCost?: number;
150
+ totalPrice?: number;
151
+ previousTotalCost?: number;
152
+ previousTotalPrice?: number;
153
+ }
154
+
155
+ export interface UsageStats {
156
+ subscription: Subscription;
157
+ totals: UsageTotals;
158
+ daily: UsageDailyEntry[];
159
+ byModel: UsageModelEntry[];
160
+ availableModels: string[];
161
+ hasCostData?: boolean;
162
+ costDataMode?: 'actual' | 'estimated_price' | 'mixed' | 'none';
163
+ hasEstimatedPriceData?: boolean;
164
+ hasActualCostData?: boolean;
165
+ costDataWarningCode?: string | null;
166
+ }
@@ -0,0 +1,40 @@
1
+ import { HttpApi } from '../http-api';
2
+ import { AuthenticationProvider } from '../auth/authentication-provider';
3
+ import {
4
+ Credentials,
5
+ AuthorizeRequest,
6
+ AuthorizeResponse,
7
+ OAuth2CallbackResponse,
8
+ } from './types';
9
+
10
+ export class CredentialsApi extends HttpApi {
11
+ constructor(baseUrl: string, auth: string | AuthenticationProvider) {
12
+ super(baseUrl, auth);
13
+ }
14
+
15
+ async authorize(provider: string, request: AuthorizeRequest): Promise<AuthorizeResponse> {
16
+ return this.httpPost<AuthorizeResponse>('/credentials/' + provider + '/authorize', request);
17
+ }
18
+
19
+ async handleOAuth2Callback(provider: string, code: string, state: string, scope?: string): Promise<OAuth2CallbackResponse> {
20
+ const params: Record<string, unknown> = { code, state };
21
+ if (scope) params.scope = scope;
22
+ return this.httpGet<OAuth2CallbackResponse>('/credentials/' + provider + '/oauth2/callback', params);
23
+ }
24
+
25
+ async list(): Promise<Credentials[]> {
26
+ return this.httpGet<Credentials[]>('/credentials');
27
+ }
28
+
29
+ async getByProvider(provider: string): Promise<Credentials[]> {
30
+ return this.httpGet<Credentials[]>('/credentials/' + provider);
31
+ }
32
+
33
+ async getById(credentialsId: string): Promise<Credentials> {
34
+ return this.httpGet<Credentials>('/credentials/all/' + credentialsId);
35
+ }
36
+
37
+ async remove(credentialsId: string): Promise<void> {
38
+ await this.httpDelete('/credentials/all/' + credentialsId);
39
+ }
40
+ }
@@ -0,0 +1,67 @@
1
+ export interface Credentials {
2
+ id?: string;
3
+ name?: string;
4
+ projectId?: string;
5
+ provider?: string;
6
+ obtainedAt?: string;
7
+ validUntil?: string;
8
+ data?: unknown;
9
+ clientId?: string;
10
+ clientSecret?: string;
11
+ apiKey?: string;
12
+ apiSecret?: string;
13
+ token?: string;
14
+ successUrl?: string;
15
+ active?: boolean;
16
+ server?: string;
17
+ port?: number;
18
+ useSsl?: boolean;
19
+ username?: string;
20
+ password?: string;
21
+ }
22
+
23
+ export interface AuthorizeRequest {
24
+ name?: string;
25
+ provider?: string;
26
+ clientId?: string;
27
+ clientSecret?: string;
28
+ scope?: string;
29
+ apiKey?: string;
30
+ apiSecret?: string;
31
+ token?: string;
32
+ successUrl?: string;
33
+ server?: string;
34
+ port?: number;
35
+ useSsl?: boolean;
36
+ username?: string;
37
+ password?: string;
38
+ }
39
+
40
+ export interface OAuth2State {
41
+ id?: string;
42
+ credentialsName?: string;
43
+ projectId?: string;
44
+ provider?: string;
45
+ status?: string;
46
+ code?: string;
47
+ scope?: string;
48
+ clientId?: string;
49
+ clientSecret?: string;
50
+ apiKey?: string;
51
+ apiSecret?: string;
52
+ token?: string;
53
+ successUrl?: string;
54
+ }
55
+
56
+ export interface AuthorizeResponse {
57
+ credentials?: Credentials;
58
+ state?: OAuth2State;
59
+ redirectUrl?: string;
60
+ }
61
+
62
+ export interface OAuth2CallbackResponse {
63
+ id?: string;
64
+ successUrl?: string;
65
+ success?: boolean;
66
+ error?: string;
67
+ }
@@ -0,0 +1,10 @@
1
+ export class ApiException extends Error {
2
+ public readonly statusCode: number;
3
+ public readonly body: string;
4
+
5
+ constructor(statusCode: number, body: string) {
6
+ super(`API Error: ${statusCode} - ${body}`);
7
+ this.statusCode = statusCode;
8
+ this.body = body;
9
+ }
10
+ }
@@ -0,0 +1,43 @@
1
+ import { HttpApi } from '../http-api';
2
+ import { Paginated } from '../paginated';
3
+ import { AuthenticationProvider } from '../auth/authentication-provider';
4
+ import { FeatureTemplate, McpToolsResponse } from './types';
5
+ import { McpServerConfiguration } from '../agents/types';
6
+
7
+ export class FeatureTemplatesApi extends HttpApi {
8
+ constructor(baseUrl: string, auth: string | AuthenticationProvider) {
9
+ super(baseUrl, auth);
10
+ }
11
+
12
+ async list(keyword?: string | null, page?: number, size?: number, extraParams?: Record<string, string>): Promise<Paginated<FeatureTemplate>> {
13
+ const { page: p, size: s } = this.normalizePageParams(page, size);
14
+ const params: Record<string, unknown> = { page: p, size: s, ...extraParams };
15
+ if (keyword) params.keyword = keyword;
16
+ return this.httpGet<Paginated<FeatureTemplate>>('/features/templates', params);
17
+ }
18
+
19
+ async get(templateId: string): Promise<FeatureTemplate> {
20
+ return this.httpGet<FeatureTemplate>('/features/templates/' + templateId);
21
+ }
22
+
23
+ async create(template: FeatureTemplate): Promise<FeatureTemplate> {
24
+ return this.httpPost<FeatureTemplate>('/features/templates', template);
25
+ }
26
+
27
+ async update(templateId: string, template: FeatureTemplate): Promise<FeatureTemplate> {
28
+ return this.httpPut<FeatureTemplate>('/features/templates/' + templateId, template);
29
+ }
30
+
31
+ async patch(templateId: string, template: FeatureTemplate): Promise<FeatureTemplate> {
32
+ return this.httpPatch<FeatureTemplate>('/features/templates/' + templateId, template);
33
+ }
34
+
35
+ async remove(templateId: string): Promise<void> {
36
+ await this.httpDelete('/features/templates/' + templateId);
37
+ }
38
+
39
+ async getMcpAvailableTools(configuration: McpServerConfiguration, credentialsId?: string): Promise<McpToolsResponse> {
40
+ const params = credentialsId ? { credentialsId } : undefined;
41
+ return this.httpPost<McpToolsResponse>('/features/templates/mcp/available-tools', configuration, params);
42
+ }
43
+ }
@@ -0,0 +1,16 @@
1
+ import { AuthenticationProvider } from '../auth/authentication-provider';
2
+ import { FeatureTemplatesApi } from './feature-templates-api';
3
+
4
+ export class FeaturesApi {
5
+ private readonly baseUrl: string;
6
+ private readonly auth: string | AuthenticationProvider;
7
+
8
+ constructor(baseUrl: string, auth: string | AuthenticationProvider) {
9
+ this.baseUrl = baseUrl;
10
+ this.auth = auth;
11
+ }
12
+
13
+ templates(): FeatureTemplatesApi {
14
+ return new FeatureTemplatesApi(this.baseUrl, this.auth);
15
+ }
16
+ }
@@ -0,0 +1,25 @@
1
+ import { FeatureConfiguration, McpServerConfiguration } from '../agents/types';
2
+ import { ToolDefinition } from '../agents/types';
3
+
4
+ export type FeatureType = 'mcp' | 'flag' | 'skill';
5
+
6
+ export interface FeatureCredentialsConfiguration {
7
+ requireCredentials?: boolean;
8
+ credentialsType?: string;
9
+ }
10
+
11
+ export interface FeatureTemplate {
12
+ id?: string;
13
+ projectId?: string;
14
+ type?: FeatureType;
15
+ name?: string;
16
+ description?: string;
17
+ logoUrl?: string;
18
+ configuration?: FeatureConfiguration;
19
+ credentialsConfiguration?: FeatureCredentialsConfiguration;
20
+ }
21
+
22
+ export interface McpToolsResponse {
23
+ tools?: ToolDefinition[];
24
+ error?: string;
25
+ }
@@ -0,0 +1,102 @@
1
+ import { ApiException } from './exceptions';
2
+ import { AuthenticationProvider } from './auth/authentication-provider';
3
+ import { ApiKeyAuthenticationProvider } from './auth/api-key-auth';
4
+
5
+ export abstract class HttpApi {
6
+ private readonly baseUrl: string;
7
+ private readonly authProvider: AuthenticationProvider;
8
+
9
+ constructor(baseUrl: string, apiKey: string | AuthenticationProvider) {
10
+ this.baseUrl = baseUrl;
11
+ this.authProvider = typeof apiKey === 'string' ? new ApiKeyAuthenticationProvider(apiKey) : apiKey;
12
+ }
13
+
14
+ protected getBaseUrl(): string {
15
+ return this.baseUrl;
16
+ }
17
+
18
+ protected getAuthProvider(): AuthenticationProvider {
19
+ return this.authProvider;
20
+ }
21
+
22
+ protected normalizePageParams(page?: number, size?: number): { page: number; size: number } {
23
+ return {
24
+ page: page === undefined || page < 1 ? 1 : page,
25
+ size: size === undefined || size < 1 ? 20 : size,
26
+ };
27
+ }
28
+
29
+ private buildHeaders(): Headers {
30
+ const headers = new Headers();
31
+ headers.set('Content-Type', 'application/json');
32
+ this.authProvider.applyHeaders(headers);
33
+ return headers;
34
+ }
35
+
36
+ private buildUrl(path: string, params?: Record<string, unknown>): string {
37
+ const url = new URL(this.baseUrl + path);
38
+ if (params) {
39
+ Object.entries(params).forEach(([key, value]) => {
40
+ if (value !== null && value !== undefined) {
41
+ url.searchParams.set(key, String(value));
42
+ }
43
+ });
44
+ }
45
+ return url.toString();
46
+ }
47
+
48
+ private async handleResponse<T>(response: Response): Promise<T> {
49
+ if (!response.ok) {
50
+ const body = await response.text();
51
+ throw new ApiException(response.status, body);
52
+ }
53
+ const text = await response.text();
54
+ return text ? JSON.parse(text) : (undefined as T);
55
+ }
56
+
57
+ protected async httpGet<T>(path: string, params?: Record<string, unknown>): Promise<T> {
58
+ const response = await fetch(this.buildUrl(path, params), {
59
+ method: 'GET',
60
+ headers: this.buildHeaders(),
61
+ });
62
+ return this.handleResponse<T>(response);
63
+ }
64
+
65
+ protected async httpPost<T>(path: string, body?: unknown, params?: Record<string, unknown>): Promise<T> {
66
+ const response = await fetch(this.buildUrl(path, params), {
67
+ method: 'POST',
68
+ headers: this.buildHeaders(),
69
+ body: body ? JSON.stringify(body) : undefined,
70
+ });
71
+ return this.handleResponse<T>(response);
72
+ }
73
+
74
+ protected async httpPut<T>(path: string, body: unknown): Promise<T> {
75
+ const response = await fetch(this.baseUrl + path, {
76
+ method: 'PUT',
77
+ headers: this.buildHeaders(),
78
+ body: JSON.stringify(body),
79
+ });
80
+ return this.handleResponse<T>(response);
81
+ }
82
+
83
+ protected async httpPatch<T>(path: string, body: unknown): Promise<T> {
84
+ const response = await fetch(this.baseUrl + path, {
85
+ method: 'PATCH',
86
+ headers: this.buildHeaders(),
87
+ body: JSON.stringify(body),
88
+ });
89
+ return this.handleResponse<T>(response);
90
+ }
91
+
92
+ protected async httpDelete(path: string): Promise<void> {
93
+ const response = await fetch(this.baseUrl + path, {
94
+ method: 'DELETE',
95
+ headers: this.buildHeaders(),
96
+ });
97
+ if (!response.ok) {
98
+ const body = await response.text();
99
+ throw new ApiException(response.status, body);
100
+ }
101
+ }
102
+ }