@almadar/integrations 2.17.0 → 2.19.0
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/dist/{contracts-DMzkrcLB.d.ts → contracts-B28G_7ur.d.ts} +16 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +174 -23
- package/dist/index.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +9 -0
- package/dist/runtime/index.js.map +1 -1
- package/package.json +8 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServiceParams } from '@almadar/core';
|
|
1
|
+
import { ServiceParamsValue, ServiceParams } from '@almadar/core';
|
|
2
2
|
import { d as IntegrationParams } from './BaseIntegration-B9lSTRQm.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -235,6 +235,19 @@ type LLMIntegrationActions = {
|
|
|
235
235
|
};
|
|
236
236
|
};
|
|
237
237
|
};
|
|
238
|
+
type MLActions = {
|
|
239
|
+
infer: {
|
|
240
|
+
params: {
|
|
241
|
+
model: string;
|
|
242
|
+
input: ServiceParamsValue;
|
|
243
|
+
};
|
|
244
|
+
result: {
|
|
245
|
+
output: ServiceParamsValue;
|
|
246
|
+
confidence: number;
|
|
247
|
+
violations: ServiceParamsValue[];
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
};
|
|
238
251
|
type YouTubeActions = {
|
|
239
252
|
search: {
|
|
240
253
|
params: {
|
|
@@ -852,6 +865,7 @@ type IntegrationContracts = {
|
|
|
852
865
|
github: GitHubActions;
|
|
853
866
|
stripe: StripeActions;
|
|
854
867
|
llm: LLMIntegrationActions;
|
|
868
|
+
ml: MLActions;
|
|
855
869
|
youtube: YouTubeActions;
|
|
856
870
|
twilio: TwilioActions;
|
|
857
871
|
email: EmailActions;
|
|
@@ -877,4 +891,4 @@ type IntegrationName = keyof IntegrationContracts;
|
|
|
877
891
|
*/
|
|
878
892
|
type IntegrationActionName<K extends IntegrationName> = keyof IntegrationContracts[K] & string;
|
|
879
893
|
|
|
880
|
-
export type { CLIActions as C, DeepAgentActions as D, EmailActions as E, GitHubActions as G, IntegrationActionName as I, LLMIntegrationActions as L, OAuthActions as O, QueueActions as Q, RedisActions as R, StorageActions as S, TwilioActions as T, YouTubeActions as Y, DockerActions as a, IntegrationContracts as b, IntegrationName as c, OtelActions as d, StripeActions as e };
|
|
894
|
+
export type { CLIActions as C, DeepAgentActions as D, EmailActions as E, GitHubActions as G, IntegrationActionName as I, LLMIntegrationActions as L, MLActions as M, OAuthActions as O, QueueActions as Q, RedisActions as R, StorageActions as S, TwilioActions as T, YouTubeActions as Y, DockerActions as a, IntegrationContracts as b, IntegrationName as c, OtelActions as d, StripeActions as e };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as IntegrationLogger, b as IntegrationErrorCode, I as IntegrationConfig, B as BaseIntegration, d as IntegrationParams, e as IntegrationResult } from './BaseIntegration-B9lSTRQm.js';
|
|
2
2
|
export { a as IntegrationError, V as ValidationError, f as ValidationResult, v as validateParams } from './BaseIntegration-B9lSTRQm.js';
|
|
3
|
-
export { C as CLIActions, D as DeepAgentActions, a as DockerActions, E as EmailActions, G as GitHubActions, I as IntegrationActionName, b as IntegrationContracts, c as IntegrationName, L as LLMIntegrationActions, O as OAuthActions, d as OtelActions, Q as QueueActions, R as RedisActions, S as StorageActions, e as StripeActions, T as TwilioActions, Y as YouTubeActions } from './contracts-
|
|
3
|
+
export { C as CLIActions, D as DeepAgentActions, a as DockerActions, E as EmailActions, G as GitHubActions, I as IntegrationActionName, b as IntegrationContracts, c as IntegrationName, L as LLMIntegrationActions, M as MLActions, O as OAuthActions, d as OtelActions, Q as QueueActions, R as RedisActions, S as StorageActions, e as StripeActions, T as TwilioActions, Y as YouTubeActions } from './contracts-B28G_7ur.js';
|
|
4
4
|
import { LogMeta } from '@almadar/core';
|
|
5
5
|
export { I as IntegrationFactory, g as getIntegrationFactory, r as resetIntegrationFactory } from './factory-TNgVDujm.js';
|
|
6
6
|
export { GitHubIntegration } from './integrations/github/index.js';
|
|
@@ -366,6 +366,15 @@ declare class LLMIntegration extends BaseIntegration {
|
|
|
366
366
|
private summarize;
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
+
declare class MLIntegration extends BaseIntegration {
|
|
370
|
+
private readonly eventsUrl;
|
|
371
|
+
private readonly timeoutMs;
|
|
372
|
+
constructor(config: IntegrationConfig);
|
|
373
|
+
execute(action: string, params: IntegrationParams): Promise<IntegrationResult>;
|
|
374
|
+
private infer;
|
|
375
|
+
private postEvent;
|
|
376
|
+
}
|
|
377
|
+
|
|
369
378
|
/**
|
|
370
379
|
* DeepAgent integration for AI code generation
|
|
371
380
|
*/
|
|
@@ -551,4 +560,4 @@ declare class DockerIntegration extends BaseIntegration {
|
|
|
551
560
|
private list;
|
|
552
561
|
}
|
|
553
562
|
|
|
554
|
-
export { type AlmadarCheckoutSession, type AlmadarCustomer, type AlmadarInvoiceFailure, type AlmadarInvoicePayment, type AlmadarPortalSession, type AlmadarStripeEvent, type AlmadarStripeEventOk, type AlmadarSubscription, type AlmadarSubscriptionStatus, type AlmadarTier, BaseIntegration, CLIIntegration, type CancelSubscriptionInput, ConsoleLogger, type CreateCheckoutInput, type CreateCustomerInput, type CreatePortalInput, DeepAgentIntegration, DockerIntegration, EmailIntegration, IntegrationConfig, type IntegrationConstructor, IntegrationErrorCode, IntegrationLogger, IntegrationResult, LLMIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, type RetryConfig, StorageIntegration, StripeIntegration, type StripePriceMap, TwilioIntegration, type UpdateSubscriptionInput, type VerifyAndParseInput, YouTubeIntegration, getIntegration, getRegisteredIntegrations, isKnownIntegration, registerIntegration, verifyAndParseStripeEvent, withRetry };
|
|
563
|
+
export { type AlmadarCheckoutSession, type AlmadarCustomer, type AlmadarInvoiceFailure, type AlmadarInvoicePayment, type AlmadarPortalSession, type AlmadarStripeEvent, type AlmadarStripeEventOk, type AlmadarSubscription, type AlmadarSubscriptionStatus, type AlmadarTier, BaseIntegration, CLIIntegration, type CancelSubscriptionInput, ConsoleLogger, type CreateCheckoutInput, type CreateCustomerInput, type CreatePortalInput, DeepAgentIntegration, DockerIntegration, EmailIntegration, IntegrationConfig, type IntegrationConstructor, IntegrationErrorCode, IntegrationLogger, IntegrationResult, LLMIntegration, MLIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, type RetryConfig, StorageIntegration, StripeIntegration, type StripePriceMap, TwilioIntegration, type UpdateSubscriptionInput, type VerifyAndParseInput, YouTubeIntegration, getIntegration, getRegisteredIntegrations, isKnownIntegration, registerIntegration, verifyAndParseStripeEvent, withRetry };
|
package/dist/index.js
CHANGED
|
@@ -1121,6 +1121,179 @@ Return ONLY valid JSON matching the schema.`,
|
|
|
1121
1121
|
};
|
|
1122
1122
|
registerIntegration("llm", LLMIntegration);
|
|
1123
1123
|
|
|
1124
|
+
// src/types.ts
|
|
1125
|
+
var IntegrationError = class extends Error {
|
|
1126
|
+
constructor(message, code = "UNKNOWN_ERROR", details) {
|
|
1127
|
+
super(message);
|
|
1128
|
+
this.name = "IntegrationError";
|
|
1129
|
+
this.code = code;
|
|
1130
|
+
this.details = details;
|
|
1131
|
+
}
|
|
1132
|
+
toJSON() {
|
|
1133
|
+
return {
|
|
1134
|
+
name: this.name,
|
|
1135
|
+
message: this.message,
|
|
1136
|
+
code: this.code,
|
|
1137
|
+
integration: this.integration,
|
|
1138
|
+
action: this.action,
|
|
1139
|
+
details: this.details
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
|
|
1144
|
+
// src/integrations/ml/index.ts
|
|
1145
|
+
var INFERRED_EVENT = "INFERRED";
|
|
1146
|
+
var INFER_FAILED_EVENT = "INFER_FAILED";
|
|
1147
|
+
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
1148
|
+
function isServiceParams(value) {
|
|
1149
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date);
|
|
1150
|
+
}
|
|
1151
|
+
function extractInferResult(response) {
|
|
1152
|
+
const emitted = (response.effectResults ?? []).find(
|
|
1153
|
+
(result) => result.effect === "emit" && result.success && isServiceParams(result.data) && result.data.event === INFERRED_EVENT
|
|
1154
|
+
);
|
|
1155
|
+
if (!emitted || !isServiceParams(emitted.data)) {
|
|
1156
|
+
return null;
|
|
1157
|
+
}
|
|
1158
|
+
const payload = emitted.data.payload;
|
|
1159
|
+
if (!isServiceParams(payload)) {
|
|
1160
|
+
return null;
|
|
1161
|
+
}
|
|
1162
|
+
if (!("output" in payload) || typeof payload.confidence !== "number" || !Array.isArray(payload.violations)) {
|
|
1163
|
+
return null;
|
|
1164
|
+
}
|
|
1165
|
+
return {
|
|
1166
|
+
output: payload.output,
|
|
1167
|
+
confidence: payload.confidence,
|
|
1168
|
+
violations: payload.violations
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
var MLIntegration = class extends BaseIntegration {
|
|
1172
|
+
constructor(config) {
|
|
1173
|
+
super(config);
|
|
1174
|
+
const baseUrl = config.env.MASAR_URL;
|
|
1175
|
+
const traitPrefix = config.env.MASAR_ML_TRAIT;
|
|
1176
|
+
if (!baseUrl || !traitPrefix) {
|
|
1177
|
+
throw new Error(
|
|
1178
|
+
"ML integration requires MASAR_URL (serving orbital host) and MASAR_ML_TRAIT (kebab-case trait name of its /events route) to be configured"
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
this.eventsUrl = `${baseUrl.replace(/\/+$/, "")}/api/${traitPrefix}/events`;
|
|
1182
|
+
this.timeoutMs = config.env.MASAR_ML_TIMEOUT_MS ? Number(config.env.MASAR_ML_TIMEOUT_MS) : DEFAULT_TIMEOUT_MS;
|
|
1183
|
+
this.logger.info("ML integration initialized", { eventsUrl: this.eventsUrl });
|
|
1184
|
+
}
|
|
1185
|
+
async execute(action, params) {
|
|
1186
|
+
const validation = this.validateParams(action, params);
|
|
1187
|
+
if (!validation.valid) {
|
|
1188
|
+
return {
|
|
1189
|
+
success: false,
|
|
1190
|
+
error: {
|
|
1191
|
+
name: "IntegrationError",
|
|
1192
|
+
message: "Validation failed",
|
|
1193
|
+
code: "VALIDATION_ERROR",
|
|
1194
|
+
details: validation.errors
|
|
1195
|
+
},
|
|
1196
|
+
metadata: this.createMetadata(action, 0)
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
const startTime = Date.now();
|
|
1200
|
+
try {
|
|
1201
|
+
let data;
|
|
1202
|
+
switch (action) {
|
|
1203
|
+
case "infer":
|
|
1204
|
+
data = await this.executeWithRetry(() => this.infer(params));
|
|
1205
|
+
break;
|
|
1206
|
+
default:
|
|
1207
|
+
throw new Error(`Unknown action: ${action}`);
|
|
1208
|
+
}
|
|
1209
|
+
return {
|
|
1210
|
+
success: true,
|
|
1211
|
+
data,
|
|
1212
|
+
metadata: this.createMetadata(action, Date.now() - startTime)
|
|
1213
|
+
};
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
return this.handleError(action, error);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
async infer(params) {
|
|
1219
|
+
const { model, input } = params;
|
|
1220
|
+
this.logger.debug("Running ML inference", { model });
|
|
1221
|
+
const response = await this.postEvent(model, input);
|
|
1222
|
+
if (!response.success) {
|
|
1223
|
+
throw new IntegrationError(
|
|
1224
|
+
`ML service reported failure: ${response.error ?? "unknown error"}`,
|
|
1225
|
+
"SERVICE_ERROR",
|
|
1226
|
+
{ model, response }
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
const failed = (response.effectResults ?? []).find(
|
|
1230
|
+
(result) => result.effect === "emit" && isServiceParams(result.data) && result.data.event === INFER_FAILED_EVENT
|
|
1231
|
+
);
|
|
1232
|
+
if (failed) {
|
|
1233
|
+
throw new IntegrationError(
|
|
1234
|
+
`ML service could not infer: ${failed.error ?? "model unavailable"}`,
|
|
1235
|
+
"SERVICE_ERROR",
|
|
1236
|
+
{ model, response }
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1239
|
+
const inferred = extractInferResult(response);
|
|
1240
|
+
if (!inferred) {
|
|
1241
|
+
throw new IntegrationError(
|
|
1242
|
+
"ML service response did not include a valid inference result",
|
|
1243
|
+
"SERVICE_ERROR",
|
|
1244
|
+
{ model, response }
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
return inferred;
|
|
1248
|
+
}
|
|
1249
|
+
async postEvent(model, input) {
|
|
1250
|
+
const controller = new AbortController();
|
|
1251
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
1252
|
+
let httpResponse;
|
|
1253
|
+
try {
|
|
1254
|
+
httpResponse = await fetch(this.eventsUrl, {
|
|
1255
|
+
method: "POST",
|
|
1256
|
+
headers: { "Content-Type": "application/json" },
|
|
1257
|
+
body: JSON.stringify({ event: "INFER", payload: { model, input } }),
|
|
1258
|
+
signal: controller.signal
|
|
1259
|
+
});
|
|
1260
|
+
} catch (error) {
|
|
1261
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
1262
|
+
throw new IntegrationError(
|
|
1263
|
+
`ML service request timed out after ${this.timeoutMs}ms (model may be cold-starting)`,
|
|
1264
|
+
"TIMEOUT_ERROR",
|
|
1265
|
+
{ model, eventsUrl: this.eventsUrl }
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
throw new IntegrationError(
|
|
1269
|
+
`ML service request failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
1270
|
+
"NETWORK_ERROR",
|
|
1271
|
+
{ model, eventsUrl: this.eventsUrl }
|
|
1272
|
+
);
|
|
1273
|
+
} finally {
|
|
1274
|
+
clearTimeout(timer);
|
|
1275
|
+
}
|
|
1276
|
+
if (!httpResponse.ok) {
|
|
1277
|
+
const body = await httpResponse.text().catch(() => "");
|
|
1278
|
+
throw new IntegrationError(
|
|
1279
|
+
`ML service responded with status ${httpResponse.status}`,
|
|
1280
|
+
"SERVICE_ERROR",
|
|
1281
|
+
{ model, status: httpResponse.status, body }
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
try {
|
|
1285
|
+
return await httpResponse.json();
|
|
1286
|
+
} catch (error) {
|
|
1287
|
+
throw new IntegrationError(
|
|
1288
|
+
`ML service returned a malformed response body: ${error instanceof Error ? error.message : String(error)}`,
|
|
1289
|
+
"SERVICE_ERROR",
|
|
1290
|
+
{ model }
|
|
1291
|
+
);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
registerIntegration("ml", MLIntegration);
|
|
1296
|
+
|
|
1124
1297
|
// src/integrations/deepagent/index.ts
|
|
1125
1298
|
var DeepAgentIntegration = class extends BaseIntegration {
|
|
1126
1299
|
constructor(config) {
|
|
@@ -1242,28 +1415,6 @@ var DeepAgentIntegration = class extends BaseIntegration {
|
|
|
1242
1415
|
}
|
|
1243
1416
|
};
|
|
1244
1417
|
registerIntegration("deepagent", DeepAgentIntegration);
|
|
1245
|
-
|
|
1246
|
-
// src/types.ts
|
|
1247
|
-
var IntegrationError = class extends Error {
|
|
1248
|
-
constructor(message, code = "UNKNOWN_ERROR", details) {
|
|
1249
|
-
super(message);
|
|
1250
|
-
this.name = "IntegrationError";
|
|
1251
|
-
this.code = code;
|
|
1252
|
-
this.details = details;
|
|
1253
|
-
}
|
|
1254
|
-
toJSON() {
|
|
1255
|
-
return {
|
|
1256
|
-
name: this.name,
|
|
1257
|
-
message: this.message,
|
|
1258
|
-
code: this.code,
|
|
1259
|
-
integration: this.integration,
|
|
1260
|
-
action: this.action,
|
|
1261
|
-
details: this.details
|
|
1262
|
-
};
|
|
1263
|
-
}
|
|
1264
|
-
};
|
|
1265
|
-
|
|
1266
|
-
// src/integrations/github/github-git.ts
|
|
1267
1418
|
async function execGit(args, cwd, env) {
|
|
1268
1419
|
return new Promise((resolve, reject) => {
|
|
1269
1420
|
const proc = spawn("git", args, {
|
|
@@ -3021,6 +3172,6 @@ var DockerIntegration = class extends BaseIntegration {
|
|
|
3021
3172
|
};
|
|
3022
3173
|
registerIntegration("docker", DockerIntegration);
|
|
3023
3174
|
|
|
3024
|
-
export { BaseIntegration, CLIIntegration, ConsoleLogger, DeepAgentIntegration, DockerIntegration, EmailIntegration, GitHubIntegration, IntegrationFactory, LLMIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, StorageIntegration, StripeIntegration, TwilioIntegration, YouTubeIntegration, getIntegration, getIntegrationFactory, getRegisteredIntegrations, isKnownIntegration, registerIntegration, resetIntegrationFactory, validateParams, verifyAndParseStripeEvent, withRetry };
|
|
3175
|
+
export { BaseIntegration, CLIIntegration, ConsoleLogger, DeepAgentIntegration, DockerIntegration, EmailIntegration, GitHubIntegration, IntegrationFactory, LLMIntegration, MLIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, StorageIntegration, StripeIntegration, TwilioIntegration, YouTubeIntegration, getIntegration, getIntegrationFactory, getRegisteredIntegrations, isKnownIntegration, registerIntegration, resetIntegrationFactory, validateParams, verifyAndParseStripeEvent, withRetry };
|
|
3025
3176
|
//# sourceMappingURL=index.js.map
|
|
3026
3177
|
//# sourceMappingURL=index.js.map
|