@axiom-lattice/core 2.1.75 → 2.1.77
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/README.md +340 -99
- package/dist/index.d.mts +558 -52
- package/dist/index.d.ts +558 -52
- package/dist/index.js +470 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +468 -96
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -424,7 +424,6 @@ declare class SqlDatabaseManager {
|
|
|
424
424
|
private static instance;
|
|
425
425
|
private databases;
|
|
426
426
|
private defaultDatabaseKeys;
|
|
427
|
-
private configStore;
|
|
428
427
|
private constructor();
|
|
429
428
|
/**
|
|
430
429
|
* Get the singleton instance
|
|
@@ -447,14 +446,9 @@ declare class SqlDatabaseManager {
|
|
|
447
446
|
* @param key - Database key to set as default
|
|
448
447
|
*/
|
|
449
448
|
setDefaultDatabase(tenantId: string, key: string): void;
|
|
450
|
-
/**
|
|
451
|
-
* Set the configuration store for on-demand database loading
|
|
452
|
-
* @param store - The database configuration store
|
|
453
|
-
*/
|
|
454
|
-
setConfigStore(store: _axiom_lattice_protocols.DatabaseConfigStore): void;
|
|
455
449
|
/**
|
|
456
450
|
* Get a database by key for a specific tenant
|
|
457
|
-
* If database is not registered
|
|
451
|
+
* If database is not registered, tries to load from the store lattice
|
|
458
452
|
* @param tenantId - Tenant identifier (required)
|
|
459
453
|
* @param key - Database key (optional, uses default if not provided)
|
|
460
454
|
* @returns ISqlDatabase instance
|
|
@@ -914,11 +908,17 @@ declare class MetricsServerManager {
|
|
|
914
908
|
private clients;
|
|
915
909
|
private configs;
|
|
916
910
|
private defaultServerKeys;
|
|
911
|
+
private _loadingPromise;
|
|
917
912
|
private constructor();
|
|
918
913
|
/**
|
|
919
914
|
* Get the singleton instance
|
|
920
915
|
*/
|
|
921
916
|
static getInstance(): MetricsServerManager;
|
|
917
|
+
/**
|
|
918
|
+
* Ensure configurations are loaded from the store lattice.
|
|
919
|
+
* Uses a promise-lock to prevent concurrent loads.
|
|
920
|
+
*/
|
|
921
|
+
private _ensureLoaded;
|
|
922
922
|
/**
|
|
923
923
|
* Get or create tenant clients map
|
|
924
924
|
*/
|
|
@@ -945,13 +945,13 @@ declare class MetricsServerManager {
|
|
|
945
945
|
* @param tenantId - Tenant identifier
|
|
946
946
|
* @param key - Server key (optional, uses default if not provided)
|
|
947
947
|
*/
|
|
948
|
-
getClient(tenantId: string, key?: string): IMetricsServerClient
|
|
948
|
+
getClient(tenantId: string, key?: string): Promise<IMetricsServerClient>;
|
|
949
949
|
/**
|
|
950
950
|
* Get metrics server configuration by key for a specific tenant
|
|
951
951
|
* @param tenantId - Tenant identifier
|
|
952
952
|
* @param key - Server key (optional, uses default if not provided)
|
|
953
953
|
*/
|
|
954
|
-
getConfig(tenantId: string, key?: string): MetricsServerConfig
|
|
954
|
+
getConfig(tenantId: string, key?: string): Promise<MetricsServerConfig>;
|
|
955
955
|
/**
|
|
956
956
|
* Check if a metrics server is registered for a tenant
|
|
957
957
|
* @param tenantId - Tenant identifier
|
|
@@ -962,11 +962,11 @@ declare class MetricsServerManager {
|
|
|
962
962
|
* Get all registered metrics server keys with their types for a tenant
|
|
963
963
|
* @param tenantId - Tenant identifier
|
|
964
964
|
*/
|
|
965
|
-
getServerKeys(tenantId: string): {
|
|
965
|
+
getServerKeys(tenantId: string): Promise<{
|
|
966
966
|
key: string;
|
|
967
967
|
type: MetricsServerType;
|
|
968
968
|
name?: string;
|
|
969
|
-
}[]
|
|
969
|
+
}[]>;
|
|
970
970
|
/**
|
|
971
971
|
* Remove a metrics server for a tenant
|
|
972
972
|
* @param tenantId - Tenant identifier
|
|
@@ -986,14 +986,6 @@ declare class MetricsServerManager {
|
|
|
986
986
|
* @param tenantId - Tenant identifier
|
|
987
987
|
*/
|
|
988
988
|
loadConfigsFromStore(store: _axiom_lattice_protocols.MetricsServerConfigStore, tenantId: string): Promise<void>;
|
|
989
|
-
/**
|
|
990
|
-
* Load all metrics server configurations from a store
|
|
991
|
-
* across all tenants and register them with this manager
|
|
992
|
-
*
|
|
993
|
-
* @param store - The metrics server configuration store
|
|
994
|
-
* @deprecated Use loadConfigsFromStore with specific tenant instead
|
|
995
|
-
*/
|
|
996
|
-
loadAllConfigsFromStore(store: _axiom_lattice_protocols.MetricsServerConfigStore): Promise<void>;
|
|
997
989
|
}
|
|
998
990
|
declare const metricsServerManager: MetricsServerManager;
|
|
999
991
|
|
|
@@ -2641,8 +2633,6 @@ interface IMessageQueueStore {
|
|
|
2641
2633
|
removeMessage(messageId: string): Promise<boolean>;
|
|
2642
2634
|
clearMessages(threadId: string): Promise<void>;
|
|
2643
2635
|
markProcessing(messageId: string): Promise<void>;
|
|
2644
|
-
markCompleted(messageId: string): Promise<void>;
|
|
2645
|
-
clearCompletedMessages(threadId: string): Promise<void>;
|
|
2646
2636
|
resetProcessingToPending(threadId: string): Promise<number>;
|
|
2647
2637
|
}
|
|
2648
2638
|
/**
|
|
@@ -2792,6 +2782,32 @@ declare const storeLatticeManager: StoreLatticeManager;
|
|
|
2792
2782
|
declare const registerStoreLattice: <TStoreType extends StoreType>(key: string, type: TStoreType, store: StoreTypeMap[TStoreType]) => void;
|
|
2793
2783
|
declare const getStoreLattice: <TStoreType extends StoreType>(key: string, type: TStoreType) => StoreLattice<TStoreType>;
|
|
2794
2784
|
|
|
2785
|
+
interface ConfigureStoresOptions {
|
|
2786
|
+
autoDisposeStores?: boolean;
|
|
2787
|
+
customStores?: Record<string, object>;
|
|
2788
|
+
}
|
|
2789
|
+
type Store = Partial<{
|
|
2790
|
+
[K in StoreType]: StoreTypeMap[K];
|
|
2791
|
+
}> & {
|
|
2792
|
+
schedule?: object;
|
|
2793
|
+
checkpoint?: object;
|
|
2794
|
+
};
|
|
2795
|
+
/**
|
|
2796
|
+
* Replace stores in the "default" lattice with the given implementations.
|
|
2797
|
+
*
|
|
2798
|
+
* Regular store keys (thread, assistant, etc.) are registered via StoreLatticeManager.
|
|
2799
|
+
* Special keys:
|
|
2800
|
+
* - `schedule`: registered via ScheduleLatticeManager with default POSTGRES type
|
|
2801
|
+
* - `checkpoint`: registered via MemoryLatticeManager (PostgresSaver / any CheckpointSaver)
|
|
2802
|
+
*
|
|
2803
|
+
* For each store: initialize() is called if available, old "default" registration is removed,
|
|
2804
|
+
* and the new store is registered. Stores with dispose() are tracked for cleanup.
|
|
2805
|
+
*
|
|
2806
|
+
* If `autoDisposeStores` is true, SIGINT/SIGTERM handlers call dispose() on exit.
|
|
2807
|
+
* Always returns a dispose function for manual cleanup.
|
|
2808
|
+
*/
|
|
2809
|
+
declare function configureStores(stores: Store, options?: ConfigureStoresOptions): Promise<() => Promise<void>>;
|
|
2810
|
+
|
|
2795
2811
|
/**
|
|
2796
2812
|
* InMemoryThreadStore
|
|
2797
2813
|
*
|
|
@@ -3217,40 +3233,161 @@ declare class InMemoryUserTenantLinkStore implements UserTenantLinkStore {
|
|
|
3217
3233
|
}
|
|
3218
3234
|
|
|
3219
3235
|
/**
|
|
3220
|
-
*
|
|
3236
|
+
* In-memory implementation of {@link ChannelInstallationStore}.
|
|
3237
|
+
*
|
|
3238
|
+
* Stores per-tenant channel installation configurations (Lark app credentials,
|
|
3239
|
+
* Slack bot tokens, etc.). Each installation defines how a specific external
|
|
3240
|
+
* app instance connects to Axiom Lattice, including fallback agent and
|
|
3241
|
+
* `rejectWhenNoBinding` behavior.
|
|
3221
3242
|
*
|
|
3222
|
-
*
|
|
3223
|
-
*
|
|
3243
|
+
* @example
|
|
3244
|
+
* ```ts
|
|
3245
|
+
* import { InMemoryChannelInstallationStore } from "@axiom-lattice/core";
|
|
3246
|
+
*
|
|
3247
|
+
* const store = new InMemoryChannelInstallationStore();
|
|
3248
|
+
* await store.createInstallation("tenant-a", "install-1", {
|
|
3249
|
+
* channel: "lark",
|
|
3250
|
+
* name: "Production Bot",
|
|
3251
|
+
* config: { appId: "cli_xxx", appSecret: "secret" },
|
|
3252
|
+
* fallbackAgentId: "agent-1",
|
|
3253
|
+
* rejectWhenNoBinding: false,
|
|
3254
|
+
* });
|
|
3255
|
+
* ```
|
|
3256
|
+
*
|
|
3257
|
+
* @see {@link ChannelInstallationStore} — Protocol interface
|
|
3258
|
+
* @see {@link InMemoryBindingStore} — Companion binding store
|
|
3224
3259
|
*/
|
|
3225
3260
|
|
|
3226
3261
|
declare class InMemoryChannelInstallationStore implements ChannelInstallationStore {
|
|
3227
3262
|
private installations;
|
|
3263
|
+
/**
|
|
3264
|
+
* Retrieves a channel installation by its unique ID.
|
|
3265
|
+
*
|
|
3266
|
+
* @param installationId - The installation identifier
|
|
3267
|
+
* @returns The {@link ChannelInstallation} or `null` if not found
|
|
3268
|
+
*/
|
|
3228
3269
|
getInstallationById(installationId: string): Promise<ChannelInstallation | null>;
|
|
3270
|
+
/**
|
|
3271
|
+
* Lists all channel installations for a tenant, optionally filtered by channel type.
|
|
3272
|
+
*
|
|
3273
|
+
* @param tenantId - Tenant identifier
|
|
3274
|
+
* @param channel - Optional channel type filter (`"lark"`, `"email"`, `"slack"`)
|
|
3275
|
+
* @returns Array of matching {@link ChannelInstallation} objects
|
|
3276
|
+
*/
|
|
3229
3277
|
getInstallationsByTenant(tenantId: string, channel?: ChannelInstallationType): Promise<ChannelInstallation[]>;
|
|
3278
|
+
/**
|
|
3279
|
+
* Creates a new channel installation for a tenant.
|
|
3280
|
+
*
|
|
3281
|
+
* @param tenantId - Tenant identifier
|
|
3282
|
+
* @param installationId - Unique installation ID (caller-defined)
|
|
3283
|
+
* @param data - {@link CreateChannelInstallationRequest} containing channel type, name, config, and fallback settings
|
|
3284
|
+
* @returns The created {@link ChannelInstallation}
|
|
3285
|
+
*/
|
|
3230
3286
|
createInstallation(tenantId: string, installationId: string, data: CreateChannelInstallationRequest): Promise<ChannelInstallation>;
|
|
3287
|
+
/**
|
|
3288
|
+
* Updates an existing channel installation. Config fields are shallow-merged.
|
|
3289
|
+
*
|
|
3290
|
+
* @param tenantId - Tenant identifier (used for isolation check)
|
|
3291
|
+
* @param installationId - Installation ID to update
|
|
3292
|
+
* @param updates - {@link UpdateChannelInstallationRequest} with fields to patch
|
|
3293
|
+
* @returns The updated {@link ChannelInstallation} or `null` if not found or tenant mismatch
|
|
3294
|
+
*/
|
|
3231
3295
|
updateInstallation(tenantId: string, installationId: string, updates: UpdateChannelInstallationRequest): Promise<ChannelInstallation | null>;
|
|
3296
|
+
/**
|
|
3297
|
+
* Deletes a channel installation.
|
|
3298
|
+
*
|
|
3299
|
+
* @param tenantId - Tenant identifier (used for isolation check)
|
|
3300
|
+
* @param installationId - Installation ID to delete
|
|
3301
|
+
* @returns `true` if deleted, `false` if not found or tenant mismatch
|
|
3302
|
+
*/
|
|
3232
3303
|
deleteInstallation(tenantId: string, installationId: string): Promise<boolean>;
|
|
3304
|
+
/**
|
|
3305
|
+
* Clears all in-memory installations. Primarily used in tests.
|
|
3306
|
+
*/
|
|
3233
3307
|
clear(): void;
|
|
3234
3308
|
}
|
|
3235
3309
|
|
|
3236
3310
|
/**
|
|
3237
|
-
*
|
|
3311
|
+
* In-memory implementation of {@link BindingRegistry}.
|
|
3312
|
+
*
|
|
3313
|
+
* Stores sender-to-agent bindings that bridge external channel identities (Lark open_id,
|
|
3314
|
+
* Slack userId, email address, etc.) to Axiom Lattice agents and threads.
|
|
3315
|
+
*
|
|
3316
|
+
* During `MessageRouter.dispatch()`, the router calls {@link resolve} to determine
|
|
3317
|
+
* which agent should handle an inbound message. The binding also controls thread
|
|
3318
|
+
* lifecycle via {@link Binding.threadMode}:
|
|
3319
|
+
*
|
|
3320
|
+
* - `"fixed"` — All messages from this sender reuse the same `threadId`.
|
|
3321
|
+
* - `"per_conversation"` — Each conversation creates a new thread.
|
|
3322
|
+
*
|
|
3323
|
+
* @example
|
|
3324
|
+
* ```ts
|
|
3325
|
+
* import { InMemoryBindingStore, setBindingRegistry } from "@axiom-lattice/core";
|
|
3326
|
+
*
|
|
3327
|
+
* const store = new InMemoryBindingStore();
|
|
3328
|
+
* setBindingRegistry(store);
|
|
3329
|
+
*
|
|
3330
|
+
* const binding = await store.create({
|
|
3331
|
+
* channel: "slack",
|
|
3332
|
+
* channelInstallationId: "install-1",
|
|
3333
|
+
* tenantId: "tenant-a",
|
|
3334
|
+
* senderId: "U12345",
|
|
3335
|
+
* agentId: "agent-1",
|
|
3336
|
+
* threadMode: "fixed",
|
|
3337
|
+
* });
|
|
3338
|
+
* ```
|
|
3238
3339
|
*
|
|
3239
|
-
*
|
|
3240
|
-
*
|
|
3340
|
+
* @see {@link BindingRegistry} — Protocol interface
|
|
3341
|
+
* @see {@link setBindingRegistry} — Global registration
|
|
3342
|
+
* @see {@link manageBindingSchema} — Agent tool for dynamic binding management
|
|
3241
3343
|
*/
|
|
3242
3344
|
|
|
3243
3345
|
declare class InMemoryBindingStore implements BindingRegistry {
|
|
3244
3346
|
private bindings;
|
|
3347
|
+
/**
|
|
3348
|
+
* Resolves a binding for the given sender across a specific channel installation.
|
|
3349
|
+
*
|
|
3350
|
+
* Called by `MessageRouter.dispatch()` during inbound message processing.
|
|
3351
|
+
* Matches on `channel + senderId + channelInstallationId + tenantId` and
|
|
3352
|
+
* requires `enabled === true`.
|
|
3353
|
+
*
|
|
3354
|
+
* @param params - Resolution parameters
|
|
3355
|
+
* @returns The matching {@link Binding} or `null` if none found.
|
|
3356
|
+
*/
|
|
3245
3357
|
resolve(params: {
|
|
3246
3358
|
channel: string;
|
|
3247
3359
|
senderId: string;
|
|
3248
3360
|
channelInstallationId: string;
|
|
3249
3361
|
tenantId: string;
|
|
3250
3362
|
}): Promise<Binding | null>;
|
|
3363
|
+
/**
|
|
3364
|
+
* Creates a new sender-to-agent binding.
|
|
3365
|
+
*
|
|
3366
|
+
* @param input - {@link CreateBindingInput} defining channel, sender, target agent, and thread mode.
|
|
3367
|
+
* @returns The newly created {@link Binding}.
|
|
3368
|
+
*/
|
|
3251
3369
|
create(input: CreateBindingInput): Promise<Binding>;
|
|
3370
|
+
/**
|
|
3371
|
+
* Updates an existing binding (e.g. changing the target agent or thread mode).
|
|
3372
|
+
*
|
|
3373
|
+
* @param id - Binding ID
|
|
3374
|
+
* @param patch - Partial {@link Binding} fields to update
|
|
3375
|
+
* @returns The updated {@link Binding}
|
|
3376
|
+
* @throws {Error} If the binding does not exist
|
|
3377
|
+
*/
|
|
3252
3378
|
update(id: string, patch: Partial<Binding>): Promise<Binding>;
|
|
3379
|
+
/**
|
|
3380
|
+
* Deletes a binding by ID.
|
|
3381
|
+
*
|
|
3382
|
+
* @param id - Binding ID
|
|
3383
|
+
*/
|
|
3253
3384
|
delete(id: string): Promise<void>;
|
|
3385
|
+
/**
|
|
3386
|
+
* Lists bindings filtered by tenant and optional channel/agent/installation.
|
|
3387
|
+
*
|
|
3388
|
+
* @param params - Filter and pagination parameters
|
|
3389
|
+
* @returns Array of matching {@link Binding} objects
|
|
3390
|
+
*/
|
|
3254
3391
|
list(params: {
|
|
3255
3392
|
channel?: string;
|
|
3256
3393
|
agentId?: string;
|
|
@@ -3259,10 +3396,25 @@ declare class InMemoryBindingStore implements BindingRegistry {
|
|
|
3259
3396
|
limit?: number;
|
|
3260
3397
|
offset?: number;
|
|
3261
3398
|
}): Promise<Binding[]>;
|
|
3399
|
+
/**
|
|
3400
|
+
* Bulk-imports bindings.
|
|
3401
|
+
*
|
|
3402
|
+
* @param bindings - Array of {@link CreateBindingInput}
|
|
3403
|
+
* @returns Array of created {@link Binding} objects
|
|
3404
|
+
*/
|
|
3262
3405
|
import(bindings: CreateBindingInput[]): Promise<Binding[]>;
|
|
3406
|
+
/**
|
|
3407
|
+
* Exports all bindings for a tenant.
|
|
3408
|
+
*
|
|
3409
|
+
* @param params - Filter by tenantId
|
|
3410
|
+
* @returns Array of {@link Binding} objects
|
|
3411
|
+
*/
|
|
3263
3412
|
export(params: {
|
|
3264
3413
|
tenantId: string;
|
|
3265
3414
|
}): Promise<Binding[]>;
|
|
3415
|
+
/**
|
|
3416
|
+
* Clears all in-memory bindings. Primarily used in tests.
|
|
3417
|
+
*/
|
|
3266
3418
|
clear(): void;
|
|
3267
3419
|
}
|
|
3268
3420
|
|
|
@@ -3287,8 +3439,6 @@ declare class InMemoryThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
3287
3439
|
removeMessage(messageId: string): Promise<boolean>;
|
|
3288
3440
|
clearMessages(threadId: string): Promise<void>;
|
|
3289
3441
|
markProcessing(messageId: string): Promise<void>;
|
|
3290
|
-
markCompleted(messageId: string): Promise<void>;
|
|
3291
|
-
clearCompletedMessages(threadId: string): Promise<void>;
|
|
3292
3442
|
resetProcessingToPending(threadId: string): Promise<number>;
|
|
3293
3443
|
}
|
|
3294
3444
|
|
|
@@ -4252,7 +4402,42 @@ declare function buildSandboxMetadataEnv(config?: RunSandboxConfig): Record<stri
|
|
|
4252
4402
|
|
|
4253
4403
|
declare function buildNamedVolumeName(prefix: "s" | "a" | "p", ...parts: Array<string | undefined>): string;
|
|
4254
4404
|
|
|
4405
|
+
/**
|
|
4406
|
+
* Sets the global {@link BindingRegistry} instance used by the channel message router.
|
|
4407
|
+
*
|
|
4408
|
+
* The registry resolves which agent/thread should handle an inbound message from an
|
|
4409
|
+
* external channel (Lark, Slack, Email, etc.). It is queried during
|
|
4410
|
+
* `MessageRouter.dispatch()` to map a sender ID to a binding.
|
|
4411
|
+
*
|
|
4412
|
+
* @example
|
|
4413
|
+
* ```ts
|
|
4414
|
+
* import { configureStores, setBindingRegistry, getStoreLattice } from "@axiom-lattice/core";
|
|
4415
|
+
* import { PostgreSQLBindingStore } from "@axiom-lattice/pg-stores";
|
|
4416
|
+
*
|
|
4417
|
+
* await configureStores({
|
|
4418
|
+
* channelBinding: new PostgreSQLBindingStore({ pool }),
|
|
4419
|
+
* });
|
|
4420
|
+
*
|
|
4421
|
+
* const bindingStore = getStoreLattice("default", "channelBinding").store as BindingRegistry;
|
|
4422
|
+
* setBindingRegistry(bindingStore);
|
|
4423
|
+
* ```
|
|
4424
|
+
*
|
|
4425
|
+
* @param r - A {@link BindingRegistry} implementation (e.g. `InMemoryBindingStore` or `PostgreSQLBindingStore`)
|
|
4426
|
+
* @see {@link getBindingRegistry}
|
|
4427
|
+
* @see {@link InMemoryBindingStore}
|
|
4428
|
+
*/
|
|
4255
4429
|
declare function setBindingRegistry(r: BindingRegistry): void;
|
|
4430
|
+
/**
|
|
4431
|
+
* Returns the globally registered {@link BindingRegistry}.
|
|
4432
|
+
*
|
|
4433
|
+
* Must be called **after** {@link setBindingRegistry}. The registry is used by
|
|
4434
|
+
* `MessageRouter.dispatch()` in `packages/gateway` to look up the agent binding
|
|
4435
|
+
* for an incoming channel message.
|
|
4436
|
+
*
|
|
4437
|
+
* @returns The active {@link BindingRegistry} instance.
|
|
4438
|
+
* @throws {Error} If the registry has not been initialized.
|
|
4439
|
+
* @see {@link setBindingRegistry}
|
|
4440
|
+
*/
|
|
4256
4441
|
declare function getBindingRegistry(): BindingRegistry;
|
|
4257
4442
|
|
|
4258
4443
|
/**
|
|
@@ -5501,12 +5686,18 @@ declare class AgentManager {
|
|
|
5501
5686
|
}, return_agent_state?: boolean): Promise<unknown>;
|
|
5502
5687
|
}
|
|
5503
5688
|
|
|
5689
|
+
/** Execution state of a thread. */
|
|
5504
5690
|
declare enum ThreadStatus {
|
|
5505
5691
|
IDLE = "idle",
|
|
5506
5692
|
BUSY = "busy",
|
|
5507
5693
|
INTERRUPTED = "interrupted",
|
|
5508
5694
|
ERROR = "error"
|
|
5509
5695
|
}
|
|
5696
|
+
/**
|
|
5697
|
+
* Snapshot of a thread's current state including queue and status.
|
|
5698
|
+
*
|
|
5699
|
+
* Used for recovery, monitoring, and external queries about thread health.
|
|
5700
|
+
*/
|
|
5510
5701
|
interface ThreadState {
|
|
5511
5702
|
threadId: string;
|
|
5512
5703
|
assistantId: string;
|
|
@@ -5520,6 +5711,25 @@ interface ThreadState {
|
|
|
5520
5711
|
pendingMessages: PendingMessage[];
|
|
5521
5712
|
pendingCount: number;
|
|
5522
5713
|
}
|
|
5714
|
+
/**
|
|
5715
|
+
* Message payload passed to {@link Agent.addMessage}.
|
|
5716
|
+
*
|
|
5717
|
+
* Supports both a legacy single-message format (`input.message`) and a
|
|
5718
|
+
* multi-message format (`input.messages[]` for mixed human/system messages).
|
|
5719
|
+
*
|
|
5720
|
+
* @example
|
|
5721
|
+
* ```ts
|
|
5722
|
+
* // Legacy single message
|
|
5723
|
+
* await agent.addMessage({ input: { message: "Hello" } });
|
|
5724
|
+
*
|
|
5725
|
+
* // Multi-message format
|
|
5726
|
+
* await agent.addMessage({
|
|
5727
|
+
* input: {
|
|
5728
|
+
* messages: [{ role: "human", content: "Hello" }, { role: "system", content: "Context" }]
|
|
5729
|
+
* }
|
|
5730
|
+
* });
|
|
5731
|
+
* ```
|
|
5732
|
+
*/
|
|
5523
5733
|
interface QueueMessage {
|
|
5524
5734
|
input: {
|
|
5525
5735
|
message?: string;
|
|
@@ -5529,6 +5739,7 @@ interface QueueMessage {
|
|
|
5529
5739
|
command?: CommandParams<any>;
|
|
5530
5740
|
custom_run_config?: any;
|
|
5531
5741
|
}
|
|
5742
|
+
/** Emitted when a thread transitions between {@link ThreadStatus} values. */
|
|
5532
5743
|
interface ThreadStatusChangedEvent {
|
|
5533
5744
|
type: "thread:status:changed";
|
|
5534
5745
|
tenantId: string;
|
|
@@ -5543,7 +5754,26 @@ interface ThreadStatusChangedEvent {
|
|
|
5543
5754
|
pendingCount?: number;
|
|
5544
5755
|
};
|
|
5545
5756
|
}
|
|
5546
|
-
|
|
5757
|
+
/**
|
|
5758
|
+
* Union of all lifecycle event names emitted by {@link Agent}.
|
|
5759
|
+
*
|
|
5760
|
+
* Used with {@link Agent.subscribe} / {@link Agent.subscribeOnce} to listen
|
|
5761
|
+
* for agent state changes. Events are automatically namespaced as
|
|
5762
|
+
* `{eventName}:{tenantId}:{threadId}`.
|
|
5763
|
+
*
|
|
5764
|
+
* | Event | Fires when |
|
|
5765
|
+
* |-------|-----------|
|
|
5766
|
+
* | `message:started` | An individual message begins processing |
|
|
5767
|
+
* | `message:completed` | An individual message finishes processing |
|
|
5768
|
+
* | `message:interrupted` | A message was interrupted (e.g. human approval) |
|
|
5769
|
+
* | `message:failed` | A message execution threw an error |
|
|
5770
|
+
* | `thread:busy` | The thread starts processing its queue |
|
|
5771
|
+
* | `thread:idle` | The thread has no more pending messages |
|
|
5772
|
+
* | `queue:pending` | A new message was added to the queue |
|
|
5773
|
+
* | `reply:ready` | Agent execution finished, AI response is available |
|
|
5774
|
+
*/
|
|
5775
|
+
type AgentLifecycleEventName = 'message:started' | 'message:completed' | 'message:interrupted' | 'message:failed' | 'thread:busy' | 'thread:idle' | 'queue:pending' | 'reply:ready';
|
|
5776
|
+
/** Emitted when the agent starts processing a queued message. */
|
|
5547
5777
|
interface MessageStartedEvent {
|
|
5548
5778
|
type: 'message:started';
|
|
5549
5779
|
messageId: string;
|
|
@@ -5551,6 +5781,12 @@ interface MessageStartedEvent {
|
|
|
5551
5781
|
timestamp: Date;
|
|
5552
5782
|
queueMode?: QueueMode;
|
|
5553
5783
|
}
|
|
5784
|
+
/**
|
|
5785
|
+
* Emitted when the agent finishes processing a queued message.
|
|
5786
|
+
*
|
|
5787
|
+
* The {@link state} field contains a LangGraph {@link StateSnapshot} which
|
|
5788
|
+
* includes the full conversation history in `state.values.messages`.
|
|
5789
|
+
*/
|
|
5554
5790
|
interface MessageCompletedEvent {
|
|
5555
5791
|
type: 'message:completed';
|
|
5556
5792
|
messageId: string;
|
|
@@ -5558,23 +5794,27 @@ interface MessageCompletedEvent {
|
|
|
5558
5794
|
duration?: number;
|
|
5559
5795
|
state?: any;
|
|
5560
5796
|
}
|
|
5797
|
+
/** Emitted when message processing throws an unrecoverable error. */
|
|
5561
5798
|
interface MessageFailedEvent {
|
|
5562
5799
|
type: 'message:failed';
|
|
5563
5800
|
messageId: string;
|
|
5564
5801
|
error: string;
|
|
5565
5802
|
timestamp: Date;
|
|
5566
5803
|
}
|
|
5804
|
+
/** Emitted when the thread has drained its queue and returned to idle. */
|
|
5567
5805
|
interface ThreadIdleEvent {
|
|
5568
5806
|
type: 'thread:idle';
|
|
5569
5807
|
timestamp: Date;
|
|
5570
5808
|
pendingCount: number;
|
|
5571
5809
|
state?: any;
|
|
5572
5810
|
}
|
|
5811
|
+
/** Emitted when a thread transitions from idle to busy (queue processing started). */
|
|
5573
5812
|
interface ThreadBusyEvent {
|
|
5574
5813
|
type: 'thread:busy';
|
|
5575
5814
|
timestamp: Date;
|
|
5576
5815
|
messageId?: string;
|
|
5577
5816
|
}
|
|
5817
|
+
/** Emitted when a message is enqueued but not yet processing. */
|
|
5578
5818
|
interface QueuePendingEvent {
|
|
5579
5819
|
type: 'queue:pending';
|
|
5580
5820
|
messageId: string;
|
|
@@ -5584,6 +5824,12 @@ interface QueuePendingEvent {
|
|
|
5584
5824
|
isHighPriority: boolean;
|
|
5585
5825
|
}
|
|
5586
5826
|
|
|
5827
|
+
/**
|
|
5828
|
+
* Parameters that uniquely identify an agent thread instance.
|
|
5829
|
+
*
|
|
5830
|
+
* Used by {@link AgentInstanceManager.getAgent} to create or retrieve
|
|
5831
|
+
* the {@link Agent} instance for a given tenant/assistant/thread combination.
|
|
5832
|
+
*/
|
|
5587
5833
|
interface AgentThreadInterface {
|
|
5588
5834
|
assistant_id: string;
|
|
5589
5835
|
thread_id: string;
|
|
@@ -5592,6 +5838,9 @@ interface AgentThreadInterface {
|
|
|
5592
5838
|
project_id?: string;
|
|
5593
5839
|
custom_run_config?: any;
|
|
5594
5840
|
}
|
|
5841
|
+
/**
|
|
5842
|
+
* Record of an async task tracked by the agent (e.g. sub-agent executions).
|
|
5843
|
+
*/
|
|
5595
5844
|
interface AsyncTaskRecord {
|
|
5596
5845
|
taskId: string;
|
|
5597
5846
|
assistantId: string;
|
|
@@ -5600,6 +5849,42 @@ interface AsyncTaskRecord {
|
|
|
5600
5849
|
createdAt: number;
|
|
5601
5850
|
completedAt?: number;
|
|
5602
5851
|
}
|
|
5852
|
+
/**
|
|
5853
|
+
* Per-tenant agent thread instance with message queue, streaming, and lifecycle events.
|
|
5854
|
+
*
|
|
5855
|
+
* Each `Agent` instance is tied to a specific `(tenant_id, assistant_id, thread_id)`
|
|
5856
|
+
* tuple. It wraps a LangGraph runnable and manages:
|
|
5857
|
+
*
|
|
5858
|
+
* - **Message queue** — Messages are enqueued via {@link addMessage} and processed
|
|
5859
|
+
* sequentially according to the thread's {@link QueueMode} (COLLECT, FOLLOWUP, STEER).
|
|
5860
|
+
* - **Streaming** — Output chunks are buffered via {@link ChunkBuffer} and consumed
|
|
5861
|
+
* through {@link chunkStream}.
|
|
5862
|
+
* - **Lifecycle events** — Emits namespaced events (`message:completed`, `reply:ready`,
|
|
5863
|
+
* `thread:idle`, etc.) via a global {@link EventBus}.
|
|
5864
|
+
* - **Abort / Resume** — Supports graceful interruption and recovery after restart.
|
|
5865
|
+
*
|
|
5866
|
+
* Instances are created and managed by {@link AgentInstanceManager}. Do not
|
|
5867
|
+
* construct directly — use `agentInstanceManager.getAgent(params)`.
|
|
5868
|
+
*
|
|
5869
|
+
* @example
|
|
5870
|
+
* ```ts
|
|
5871
|
+
* const agent = agentInstanceManager.getAgent({
|
|
5872
|
+
* assistant_id: "agent-1",
|
|
5873
|
+
* thread_id: "thread-abc",
|
|
5874
|
+
* tenant_id: "tenant-x",
|
|
5875
|
+
* });
|
|
5876
|
+
*
|
|
5877
|
+
* // Subscribe to completion
|
|
5878
|
+
* agent.subscribeOnce("message:completed", (evt) => {
|
|
5879
|
+
* console.log("Agent finished:", evt.state);
|
|
5880
|
+
* });
|
|
5881
|
+
*
|
|
5882
|
+
* // Enqueue a message
|
|
5883
|
+
* const result = await agent.addMessage({
|
|
5884
|
+
* input: { message: "Hello!" },
|
|
5885
|
+
* });
|
|
5886
|
+
* ```
|
|
5887
|
+
*/
|
|
5603
5888
|
declare class Agent {
|
|
5604
5889
|
private queueStore;
|
|
5605
5890
|
private stateChecker;
|
|
@@ -5614,13 +5899,37 @@ declare class Agent {
|
|
|
5614
5899
|
queueMode: ThreadQueueConfig;
|
|
5615
5900
|
private isWaitingForQueueEnd;
|
|
5616
5901
|
asyncTasks: AsyncTaskRecord[];
|
|
5902
|
+
/**
|
|
5903
|
+
* Constructs an Agent instance.
|
|
5904
|
+
*
|
|
5905
|
+
* Prefer {@link AgentInstanceManager.getAgent} over direct construction — it
|
|
5906
|
+
* ensures a single instance per thread.
|
|
5907
|
+
*
|
|
5908
|
+
* @param params - {@link AgentThreadInterface}
|
|
5909
|
+
*/
|
|
5617
5910
|
constructor({ assistant_id, thread_id, tenant_id, workspace_id, project_id, custom_run_config, }: AgentThreadInterface);
|
|
5618
5911
|
private getHumanPendingContent;
|
|
5619
5912
|
/**
|
|
5620
5913
|
* Initialize with message queue store
|
|
5621
5914
|
*/
|
|
5622
5915
|
setQueueStore(store: IMessageQueueStore): void;
|
|
5916
|
+
/**
|
|
5917
|
+
* Push a chunk into the streaming buffer for this thread.
|
|
5918
|
+
*
|
|
5919
|
+
* Consumers read chunks via {@link chunkStream}.
|
|
5920
|
+
*
|
|
5921
|
+
* @param content - The message chunk to buffer
|
|
5922
|
+
*/
|
|
5623
5923
|
addChunk(content: MessageChunk): Promise<void>;
|
|
5924
|
+
/**
|
|
5925
|
+
* Returns an async iterator over new chunks since the given message ID.
|
|
5926
|
+
*
|
|
5927
|
+
* Used by SSE endpoints to stream agent output to clients in real time.
|
|
5928
|
+
*
|
|
5929
|
+
* @param message_id - The client message ID to start streaming from
|
|
5930
|
+
* @param stopTypes - Optional chunk types that terminate the stream
|
|
5931
|
+
* @returns An async iterable yielding {@link MessageChunk} objects
|
|
5932
|
+
*/
|
|
5624
5933
|
chunkStream(message_id: string, stopTypes?: MessageChunkType[]): {
|
|
5625
5934
|
[Symbol.asyncIterator]: () => AsyncGenerator<MessageChunk, void, unknown>;
|
|
5626
5935
|
};
|
|
@@ -5638,22 +5947,50 @@ declare class Agent {
|
|
|
5638
5947
|
private getQueueStore;
|
|
5639
5948
|
private getDefaultQueueConfig;
|
|
5640
5949
|
/**
|
|
5641
|
-
*
|
|
5950
|
+
* Override the thread's queue processing mode.
|
|
5951
|
+
*
|
|
5952
|
+
* @param config - Partial {@link ThreadQueueConfig} (e.g. `{ mode: QueueMode.FOLLOWUP }`)
|
|
5642
5953
|
*/
|
|
5643
5954
|
setQueueConfig(config: Partial<ThreadQueueConfig>): Promise<void>;
|
|
5644
5955
|
/**
|
|
5645
|
-
*
|
|
5956
|
+
* Abort any ongoing queue processing without clearing the queue.
|
|
5957
|
+
*
|
|
5958
|
+
* Used internally by STEER mode to interrupt the current execution so the
|
|
5959
|
+
* steer message can be processed next. For a full abort that also clears
|
|
5960
|
+
* pending messages, use {@link abort}.
|
|
5961
|
+
*
|
|
5962
|
+
* @see {@link abort}
|
|
5646
5963
|
*/
|
|
5647
5964
|
stopQueueProcessor(): void;
|
|
5648
5965
|
/**
|
|
5649
|
-
*
|
|
5650
|
-
*
|
|
5651
|
-
*
|
|
5966
|
+
* Enqueue a message for this thread.
|
|
5967
|
+
*
|
|
5968
|
+
* Messages are always queued; the queue processor starts automatically if idle.
|
|
5969
|
+
* Returns immediately with the message ID — execution is asynchronous.
|
|
5970
|
+
*
|
|
5971
|
+
* **Queue modes** (via the optional `mode` param):
|
|
5972
|
+
* - `COLLECT` (default) — Batch multiple pending messages into one agent call.
|
|
5973
|
+
* - `FOLLOWUP` — Process messages one at a time in order.
|
|
5974
|
+
* - `STEER` — High-priority, inserted at queue head, interrupts current processing.
|
|
5652
5975
|
*
|
|
5653
|
-
* Supports both legacy
|
|
5654
|
-
*
|
|
5655
|
-
*
|
|
5656
|
-
*
|
|
5976
|
+
* **Format**: Supports both `input.message` (legacy string) and `input.messages[]`
|
|
5977
|
+
* (array of `{ role, content }` objects). The array form takes precedence.
|
|
5978
|
+
*
|
|
5979
|
+
* The `custom_run_config` field is round-tripped through the queue and emitted
|
|
5980
|
+
* back in {@link ReplyReadyEvent}, enabling callers to attach routing metadata
|
|
5981
|
+
* (e.g. `_replyTarget` for channel reply).
|
|
5982
|
+
*
|
|
5983
|
+
* @param queueMessage - The message to enqueue
|
|
5984
|
+
* @param mode - Optional queue mode override (defaults to thread's current mode)
|
|
5985
|
+
* @returns `{ queued: true, executed: false, messageId }` — execution happens asynchronously
|
|
5986
|
+
*
|
|
5987
|
+
* @example
|
|
5988
|
+
* ```ts
|
|
5989
|
+
* await agent.addMessage({
|
|
5990
|
+
* input: { message: "Hello" },
|
|
5991
|
+
* custom_run_config: { _replyTarget: { adapterChannel: "lark", rawTarget: { chatId: "xxx" } } },
|
|
5992
|
+
* });
|
|
5993
|
+
* ```
|
|
5657
5994
|
*/
|
|
5658
5995
|
addMessage(queueMessage: QueueMessage, mode?: QueueMode): Promise<{
|
|
5659
5996
|
queued: boolean;
|
|
@@ -5661,8 +5998,13 @@ declare class Agent {
|
|
|
5661
5998
|
executed: boolean;
|
|
5662
5999
|
}>;
|
|
5663
6000
|
/**
|
|
5664
|
-
* Start queue processor if not already running
|
|
5665
|
-
*
|
|
6001
|
+
* Start the queue processor if it is not already running.
|
|
6002
|
+
*
|
|
6003
|
+
* Called automatically by {@link addMessage} and {@link resumeTask}.
|
|
6004
|
+
* Safe to call externally — it is a no-op if processing is already active.
|
|
6005
|
+
*
|
|
6006
|
+
* Emits `thread:busy` before starting, and starts the {@link waitingForQueueEnd}
|
|
6007
|
+
* loop with a fresh {@link AbortController}.
|
|
5666
6008
|
*/
|
|
5667
6009
|
startQueueProcessorIfNeeded(): Promise<void>;
|
|
5668
6010
|
/**
|
|
@@ -5673,24 +6015,56 @@ declare class Agent {
|
|
|
5673
6015
|
* Add reminder message for interrupted tasks
|
|
5674
6016
|
*/
|
|
5675
6017
|
private addReminderMessage;
|
|
6018
|
+
/**
|
|
6019
|
+
* Returns a LangGraph StateSnapshot for this thread.
|
|
6020
|
+
*
|
|
6021
|
+
* Includes `state.values.messages` (full conversation history) and
|
|
6022
|
+
* `state.tasks` / `state.next` (execution progress).
|
|
6023
|
+
*/
|
|
5676
6024
|
getCurrentState(): Promise<_langchain_langgraph.StateSnapshot>;
|
|
6025
|
+
/**
|
|
6026
|
+
* Returns the conversation history as normalized message objects.
|
|
6027
|
+
*
|
|
6028
|
+
* Filters to `human`, `ai`, and `tool` message types. Each entry has
|
|
6029
|
+
* `{ id, role, content }` plus any LangChain kwargs.
|
|
6030
|
+
*
|
|
6031
|
+
* @returns Array of message objects with `id`, `role`, and `content`
|
|
6032
|
+
*/
|
|
5677
6033
|
getCurrentMessages(): Promise<{
|
|
5678
6034
|
id: string | undefined;
|
|
5679
6035
|
role: _langchain_core_messages.MessageType;
|
|
5680
6036
|
content: string | (langchain.ContentBlock | langchain.ContentBlock.Text)[];
|
|
5681
6037
|
}[]>;
|
|
5682
6038
|
get_draw_graph(): Promise<string>;
|
|
6039
|
+
/**
|
|
6040
|
+
* Determine the current thread execution status.
|
|
6041
|
+
*
|
|
6042
|
+
* Checks LangGraph's `state.tasks` for interrupts and `state.next` for
|
|
6043
|
+
* pending steps.
|
|
6044
|
+
*
|
|
6045
|
+
* @returns {@link ThreadStatus} — `IDLE`, `BUSY`, or `INTERRUPTED`
|
|
6046
|
+
*/
|
|
5683
6047
|
getRunStatus(): Promise<ThreadStatus>;
|
|
5684
6048
|
/**
|
|
5685
|
-
* Resume
|
|
5686
|
-
*
|
|
5687
|
-
*
|
|
6049
|
+
* Resume processing after a server restart.
|
|
6050
|
+
*
|
|
6051
|
+
* Resets any stuck "processing" messages back to "pending" and restarts the
|
|
6052
|
+
* queue processor. Skips threads that are in `INTERRUPTED` state (the
|
|
6053
|
+
* interruption was intentional).
|
|
6054
|
+
*
|
|
6055
|
+
* Called during gateway startup to recover threads that were mid-execution
|
|
6056
|
+
* when the server went down.
|
|
5688
6057
|
*/
|
|
5689
6058
|
resumeTask(): Promise<void>;
|
|
5690
6059
|
/**
|
|
5691
|
-
*
|
|
5692
|
-
*
|
|
5693
|
-
*
|
|
6060
|
+
* Fully abort all activity on this thread.
|
|
6061
|
+
*
|
|
6062
|
+
* Aborts any in-flight agent execution (via {@link AbortController}) and
|
|
6063
|
+
* clears all pending and processing messages from the queue. Also marks
|
|
6064
|
+
* the chunk buffer thread as aborted so streaming consumers can detect it.
|
|
6065
|
+
*
|
|
6066
|
+
* Unlike {@link stopQueueProcessor}, this is a destructive abort — the
|
|
6067
|
+
* queue is drained.
|
|
5694
6068
|
*/
|
|
5695
6069
|
abort(): Promise<void>;
|
|
5696
6070
|
/**
|
|
@@ -5698,25 +6072,59 @@ declare class Agent {
|
|
|
5698
6072
|
*/
|
|
5699
6073
|
isAborted(): boolean;
|
|
5700
6074
|
/**
|
|
5701
|
-
* Subscribe to lifecycle
|
|
5702
|
-
*
|
|
6075
|
+
* Subscribe to a lifecycle event for this specific thread.
|
|
6076
|
+
*
|
|
6077
|
+
* Event names are namespaced as `{eventName}:{tenantId}:{threadId}` so
|
|
6078
|
+
* listeners only receive events for this agent instance.
|
|
6079
|
+
*
|
|
6080
|
+
* @param eventName - One of {@link AgentLifecycleEventName}
|
|
6081
|
+
* @param callback - Handler receiving the event data payload
|
|
6082
|
+
*
|
|
6083
|
+
* @example
|
|
6084
|
+
* ```ts
|
|
6085
|
+
* agent.subscribe("message:completed", (evt) => {
|
|
6086
|
+
* console.log("AI response:", evt.state?.values?.messages);
|
|
6087
|
+
* });
|
|
6088
|
+
* ```
|
|
5703
6089
|
*/
|
|
5704
6090
|
subscribe(eventName: AgentLifecycleEventName, callback: (data: any) => void): void;
|
|
5705
6091
|
/**
|
|
5706
|
-
*
|
|
6092
|
+
* Remove a previously registered event listener.
|
|
6093
|
+
*
|
|
6094
|
+
* @param eventName - The event that was subscribed to
|
|
6095
|
+
* @param callback - The same function reference used in {@link subscribe}
|
|
5707
6096
|
*/
|
|
5708
6097
|
unsubscribe(eventName: AgentLifecycleEventName, callback: (data: any) => void): void;
|
|
5709
6098
|
/**
|
|
5710
|
-
* Subscribe to lifecycle
|
|
6099
|
+
* Subscribe to a lifecycle event once — the listener is removed after the
|
|
6100
|
+
* first invocation.
|
|
6101
|
+
*
|
|
6102
|
+
* Ideal for one-shot async patterns (e.g. waiting for `reply:ready` before
|
|
6103
|
+
* sending a channel reply).
|
|
6104
|
+
*
|
|
6105
|
+
* @param eventName - One of {@link AgentLifecycleEventName}
|
|
6106
|
+
* @param callback - Handler receiving the event data payload
|
|
5711
6107
|
*/
|
|
5712
6108
|
subscribeOnce(eventName: AgentLifecycleEventName, callback: (data: any) => void): void;
|
|
5713
6109
|
/**
|
|
5714
6110
|
* Publish lifecycle event (internal use)
|
|
5715
6111
|
*/
|
|
5716
6112
|
private publish;
|
|
6113
|
+
/**
|
|
6114
|
+
* Track a sub-agent async task spawned by this agent.
|
|
6115
|
+
*
|
|
6116
|
+
* Tasks are monitored by the agent task consumer in `packages/gateway`
|
|
6117
|
+
* and their status can be polled via {@link getAsyncTasks}.
|
|
6118
|
+
*/
|
|
5717
6119
|
addAsyncTask(task: AsyncTaskRecord): void;
|
|
5718
6120
|
getAsyncTasks(): AsyncTaskRecord[];
|
|
5719
6121
|
getAsyncTask(taskId: string): AsyncTaskRecord | undefined;
|
|
6122
|
+
/**
|
|
6123
|
+
* Update the status of a tracked async task.
|
|
6124
|
+
*
|
|
6125
|
+
* Terminal states (`completed`, `failed`, `cancelled`) automatically
|
|
6126
|
+
* set `completedAt` to the current timestamp.
|
|
6127
|
+
*/
|
|
5720
6128
|
updateAsyncTaskStatus(taskId: string, status: AsyncTaskRecord['status']): void;
|
|
5721
6129
|
}
|
|
5722
6130
|
|
|
@@ -5816,6 +6224,104 @@ declare function validateEncryptionKey(): void;
|
|
|
5816
6224
|
*/
|
|
5817
6225
|
declare function clearEncryptionKeyCache(): void;
|
|
5818
6226
|
|
|
6227
|
+
/**
|
|
6228
|
+
* Factory function type for creating custom middleware instances.
|
|
6229
|
+
*
|
|
6230
|
+
* Receives the raw `config` object from the database (excluding the `key` field)
|
|
6231
|
+
* and returns a LangChain `AgentMiddleware` instance, either synchronously or asynchronously.
|
|
6232
|
+
*
|
|
6233
|
+
* @example
|
|
6234
|
+
* ```ts
|
|
6235
|
+
* const factory: CustomMiddlewareFactory = (config) =>
|
|
6236
|
+
* createMiddleware({
|
|
6237
|
+
* name: "MyMiddleware",
|
|
6238
|
+
* wrapModelCall: async (request, handler) => {
|
|
6239
|
+
* console.log(`[${config.logLevel}] Model call`);
|
|
6240
|
+
* return handler(request);
|
|
6241
|
+
* },
|
|
6242
|
+
* });
|
|
6243
|
+
* ```
|
|
6244
|
+
*/
|
|
6245
|
+
type CustomMiddlewareFactory = (config: Record<string, any>) => Promise<AgentMiddleware> | AgentMiddleware;
|
|
6246
|
+
/**
|
|
6247
|
+
* Global registry for external applications to register custom middleware factories.
|
|
6248
|
+
*
|
|
6249
|
+
* Applications write their own middleware (auth, audit, custom tools, etc.) without
|
|
6250
|
+
* modifying core source code. Once registered, middleware can be enabled per-agent via
|
|
6251
|
+
* the database config using `type: "custom"` in the agent's `graphDefinition.middleware` array.
|
|
6252
|
+
*
|
|
6253
|
+
* @example Register and use
|
|
6254
|
+
* ```ts
|
|
6255
|
+
* // 1. App startup — register a factory
|
|
6256
|
+
* CustomMiddlewareRegistry.register("audit-logger", (config) =>
|
|
6257
|
+
* createMiddleware({
|
|
6258
|
+
* name: "AuditLogger",
|
|
6259
|
+
* wrapModelCall: async (r, h) => { console.log("audit:", config.level); return h(r); },
|
|
6260
|
+
* }),
|
|
6261
|
+
* );
|
|
6262
|
+
*
|
|
6263
|
+
* // 2. Database config for an agent
|
|
6264
|
+
* // {
|
|
6265
|
+
* // "id": "mw-001",
|
|
6266
|
+
* // "type": "custom",
|
|
6267
|
+
* // "enabled": true,
|
|
6268
|
+
* // "config": { "key": "audit-logger", "level": "debug" }
|
|
6269
|
+
* // }
|
|
6270
|
+
* ```
|
|
6271
|
+
*
|
|
6272
|
+
* @remarks
|
|
6273
|
+
* - Register factories **before** building agents (typically at app startup).
|
|
6274
|
+
* - Duplicate keys overwrite previous registrations.
|
|
6275
|
+
* - Unregistered keys are skipped with a console warning at agent build time.
|
|
6276
|
+
*/
|
|
6277
|
+
declare class CustomMiddlewareRegistry {
|
|
6278
|
+
private static factories;
|
|
6279
|
+
/**
|
|
6280
|
+
* Register a custom middleware factory under the given key.
|
|
6281
|
+
*
|
|
6282
|
+
* The key is referenced by `config.key` in the database middleware configuration.
|
|
6283
|
+
* When an agent is built, the framework looks up this key and calls the factory
|
|
6284
|
+
* with the remaining config fields.
|
|
6285
|
+
*
|
|
6286
|
+
* @param key - Unique identifier, referenced in database config as `config.key`
|
|
6287
|
+
* @param factory - Function that receives config (minus `key`) and returns an AgentMiddleware
|
|
6288
|
+
*
|
|
6289
|
+
* @example
|
|
6290
|
+
* ```ts
|
|
6291
|
+
* CustomMiddlewareRegistry.register("my-logger", (config) =>
|
|
6292
|
+
* createMiddleware({ name: "Logger", beforeAgent: async () => { ... } }),
|
|
6293
|
+
* );
|
|
6294
|
+
* ```
|
|
6295
|
+
*/
|
|
6296
|
+
static register(key: string, factory: CustomMiddlewareFactory): void;
|
|
6297
|
+
/**
|
|
6298
|
+
* Remove a previously registered factory.
|
|
6299
|
+
*
|
|
6300
|
+
* @param key - The factory key to unregister
|
|
6301
|
+
* @returns `true` if a factory was removed, `false` if the key was not found
|
|
6302
|
+
*/
|
|
6303
|
+
static unregister(key: string): boolean;
|
|
6304
|
+
/**
|
|
6305
|
+
* Look up a factory by key.
|
|
6306
|
+
*
|
|
6307
|
+
* @param key - The factory key
|
|
6308
|
+
* @returns The factory function, or `undefined` if not registered
|
|
6309
|
+
*/
|
|
6310
|
+
static get(key: string): CustomMiddlewareFactory | undefined;
|
|
6311
|
+
/**
|
|
6312
|
+
* Check whether a factory is registered under the given key.
|
|
6313
|
+
*
|
|
6314
|
+
* @param key - The factory key to check
|
|
6315
|
+
*/
|
|
6316
|
+
static has(key: string): boolean;
|
|
6317
|
+
/**
|
|
6318
|
+
* Get all currently registered factory keys.
|
|
6319
|
+
*
|
|
6320
|
+
* @returns Array of registered key strings
|
|
6321
|
+
*/
|
|
6322
|
+
static list(): string[];
|
|
6323
|
+
}
|
|
6324
|
+
|
|
5819
6325
|
/**
|
|
5820
6326
|
* Create middleware that provides widget rendering capabilities.
|
|
5821
6327
|
*
|
|
@@ -5902,4 +6408,4 @@ interface UnknownToolHandlerConfig {
|
|
|
5902
6408
|
*/
|
|
5903
6409
|
declare function createUnknownToolHandlerMiddleware(config?: UnknownToolHandlerConfig): AgentMiddleware;
|
|
5904
6410
|
|
|
5905
|
-
export { AGENT_TASK_EVENT, type AddMessageParams, Agent, type AgentClient, type AgentExecutor, AgentInstanceManager, type AgentLattice, AgentLatticeManager, type AgentLifecycleEventName, AgentManager, type AgentStreamExecutor, type AgentThreadInterface, BUILTIN_SKILLS, type BackendFactory, type BackendProtocol, type BufferStats, type Chunk, ChunkBuffer, ChunkBufferLatticeManager, type ColumnInfo, CompositeBackend, ConsoleLoggerClient, type CreateProcessingAgentParams, type CreateSandboxProviderConfig, type CronFields, CustomMetricsClient, type DatabaseConfig, type DatabaseType, DaytonaInstance, DaytonaProvider, type DaytonaProviderConfig, DefaultScheduleClient, E2BInstance, E2BProvider, type E2BProviderConfig, EMPTY_CONTENT_WARNING, type EditResult, type EmbeddingsLatticeInterface, EmbeddingsLatticeManager, type EnsureMicrosandboxInput, type FileData, type FileInfo, FileSystemSkillStore, type FileSystemSkillStoreOptions, FilesystemBackend, type FsEntry, type GrepMatch, type IMessageQueueStore, type IMetricsServerClient, type ISqlDatabase, InMemoryAssistantStore, InMemoryBindingStore, InMemoryChannelInstallationStore, InMemoryChunkBuffer, InMemoryDatabaseConfigStore, InMemoryMailboxStore, InMemoryTaskListStore, InMemoryTenantStore, InMemoryThreadMessageQueueStore, InMemoryThreadStore, InMemoryUserStore, InMemoryUserTenantLinkStore, LINE_NUMBER_WIDTH, type LangGraphStateChecker, type LoggerLattice, LoggerLatticeManager, MAX_LINE_LENGTH, type MailboxMessage, type MailboxStore, type McpLatticeInterface, McpLatticeManager, type McpServerInfo, MemoryBackend, MemoryLatticeManager, MemoryQueueClient, MemoryScheduleStorage, type MessageCompletedEvent, type MessageFailedEvent, type MessageStartedEvent, MessageType, MetricsServerManager, MicrosandboxRemoteInstance, MicrosandboxRemoteProvider, type MicrosandboxRemoteProviderClient, type MicrosandboxRemoteProviderConfig, MicrosandboxServiceClient, type MicrosandboxServiceClientConfig, type MicrosandboxShellExecInput, type ModelConfig, type ModelLatticeInterface, ModelLatticeManager, MysqlDatabase, type PendingMessage, PinoLoggerClient, PostgresDatabase, PrometheusClient, type QueryResult, type QueueLattice, QueueLatticeManager, QueueMode, type QueuePendingEvent, RemoteSandboxInstance, RemoteSandboxProvider, type RemoteSandboxProviderConfig, type RunSandboxConfig, type RuntimeModelConfig, type SandboxFileInfo, type SandboxFileService, SandboxFilesystem, type SandboxInstance, type SandboxIsolationLevel, SandboxLatticeManager, type SandboxManagerProtocol, type SandboxProvider, type SandboxShellService, SandboxSkillStore, type SandboxSkillStoreOptions, type SandboxVolumeDefinition, type ScheduleLattice, ScheduleLatticeManager, type SchedulerMiddlewareOptions, SemanticMetricsClient, type SkillLattice, SkillLatticeManager, type SkillMeta, type SkillResource, SqlDatabaseManager, type StateAndStore, StateBackend, StoreBackend, type StoreLattice, StoreLatticeManager, type StoreType, type StoreTypeMap, TOOL_RESULT_TOKEN_LIMIT, TRUNCATION_GUIDANCE, type TableInfo, type TableSchema, type TaskEvent, type TaskListStore, type TaskSpec, TaskStatus, type TaskUpdatable, TeamAgentGraphBuilder, type TeamConfig, type TeamMiddlewareOptions, type TeamTask, type TeammateSpec, type TeammateToolsOptions, type ThreadBuffer, type ThreadBufferConfig, type ThreadBusyEvent, type ThreadIdleEvent, type ThreadInfo, type ThreadQueueConfig, type ThreadState, ThreadStatus, type ThreadStatusChangedEvent, type ToolDefinition, type ToolLattice, ToolLatticeManager, type TopologyEdge, type UnknownToolHandlerConfig, type VectorStoreLatticeInterface, VectorStoreLatticeManager, VolumeFilesystem, type VolumeFsClient, type WriteResult, agentInstanceManager, agentLatticeManager, buildGrepResultsDict, buildNamedVolumeName, buildSandboxMetadataEnv, buildSkillFile, checkEmptyContent, clearEncryptionKeyCache, computeSandboxName, createAgentTeam, createExecuteSqlQueryTool, createFileData, createInfoSqlTool, createListMetricsDataSourcesTool, createListMetricsServersTool, createListTablesSqlTool, createModelSelectorMiddleware, createProcessingAgent, createQueryCheckerSqlTool, createQueryMetricDefinitionTool, createQueryMetricsListTool, createQuerySemanticMetricDataTool, createQuerySqlTool, createQueryTableDefinitionTool, createQueryTablesListTool, createSandboxProvider, createSchedulerMiddleware, createTeamMiddleware, createTeammateTools, createUnknownToolHandlerMiddleware, createWidgetMiddleware, decrypt, describeCronExpression, embeddingsLatticeManager, encrypt, ensureBuiltinAgentsForTenant, eventBus, eventBus as eventBusDefault, extractFetcherError, fileDataToString, formatContentWithLineNumbers, formatGrepMatches, formatGrepResults, formatReadResponse, getAgentClient, getAgentConfig, getAllAgentConfigs, getAllBuiltInSkillMetas, getAllToolDefinitions, getBindingRegistry, getBuiltInSkillContent, getBuiltInSkillMeta, getBuiltInSkillNames, getCheckpointSaver, getChunkBuffer, getEmbeddingsClient, getEmbeddingsLattice, getEncryptionKey, getLoggerLattice, getModelLattice, getNextCronTime, getQueueLattice, getSandBoxManager, getScheduleLattice, getStoreLattice, getToolClient, getToolDefinition, getToolLattice, getVectorStoreClient, getVectorStoreLattice, globSearchFiles, grepMatchesFromFiles, grepSearchFiles, hasChunkBuffer, isBuiltInSkill, isUsingDefaultKey, isValidCronExpression, isValidSandboxName, isValidSkillName, loggerLatticeManager, mcpManager, metricsServerManager, modelLatticeManager, normalizeSandboxName, parseCronExpression, parseSkillFrontmatter, performStringReplacement, queueLatticeManager, registerAgentLattice, registerAgentLatticeWithTenant, registerAgentLattices, registerCheckpointSaver, registerChunkBuffer, registerEmbeddingsLattice, registerExistingTool, registerLoggerLattice, registerModelLattice, registerQueueLattice, registerScheduleLattice, registerStoreLattice, registerTeammateAgent, registerToolLattice, registerVectorStoreLattice, sandboxLatticeManager, sanitizeToolCallId, scheduleLatticeManager, setBindingRegistry, skillLatticeManager, sqlDatabaseManager, storeLatticeManager, toolLatticeManager, truncateIfTooLong, unregisterTeammateAgent, updateFileData, validateAgentInput, validateEncryptionKey, validatePath, validateSkillName, validateToolInput, vectorStoreLatticeManager };
|
|
6411
|
+
export { AGENT_TASK_EVENT, type AddMessageParams, Agent, type AgentClient, type AgentExecutor, AgentInstanceManager, type AgentLattice, AgentLatticeManager, type AgentLifecycleEventName, AgentManager, type AgentStreamExecutor, type AgentThreadInterface, BUILTIN_SKILLS, type BackendFactory, type BackendProtocol, type BufferStats, type Chunk, ChunkBuffer, ChunkBufferLatticeManager, type ColumnInfo, CompositeBackend, ConsoleLoggerClient, type CreateProcessingAgentParams, type CreateSandboxProviderConfig, type CronFields, CustomMetricsClient, type CustomMiddlewareFactory, CustomMiddlewareRegistry, type DatabaseConfig, type DatabaseType, DaytonaInstance, DaytonaProvider, type DaytonaProviderConfig, DefaultScheduleClient, E2BInstance, E2BProvider, type E2BProviderConfig, EMPTY_CONTENT_WARNING, type EditResult, type EmbeddingsLatticeInterface, EmbeddingsLatticeManager, type EnsureMicrosandboxInput, type FileData, type FileInfo, FileSystemSkillStore, type FileSystemSkillStoreOptions, FilesystemBackend, type FsEntry, type GrepMatch, type IMessageQueueStore, type IMetricsServerClient, type ISqlDatabase, InMemoryAssistantStore, InMemoryBindingStore, InMemoryChannelInstallationStore, InMemoryChunkBuffer, InMemoryDatabaseConfigStore, InMemoryMailboxStore, InMemoryTaskListStore, InMemoryTenantStore, InMemoryThreadMessageQueueStore, InMemoryThreadStore, InMemoryUserStore, InMemoryUserTenantLinkStore, LINE_NUMBER_WIDTH, type LangGraphStateChecker, type LoggerLattice, LoggerLatticeManager, MAX_LINE_LENGTH, type MailboxMessage, type MailboxStore, type McpLatticeInterface, McpLatticeManager, type McpServerInfo, MemoryBackend, MemoryLatticeManager, MemoryQueueClient, MemoryScheduleStorage, type MessageCompletedEvent, type MessageFailedEvent, type MessageStartedEvent, MessageType, MetricsServerManager, MicrosandboxRemoteInstance, MicrosandboxRemoteProvider, type MicrosandboxRemoteProviderClient, type MicrosandboxRemoteProviderConfig, MicrosandboxServiceClient, type MicrosandboxServiceClientConfig, type MicrosandboxShellExecInput, type ModelConfig, type ModelLatticeInterface, ModelLatticeManager, MysqlDatabase, type PendingMessage, PinoLoggerClient, PostgresDatabase, PrometheusClient, type QueryResult, type QueueLattice, QueueLatticeManager, QueueMode, type QueuePendingEvent, RemoteSandboxInstance, RemoteSandboxProvider, type RemoteSandboxProviderConfig, type RunSandboxConfig, type RuntimeModelConfig, type SandboxFileInfo, type SandboxFileService, SandboxFilesystem, type SandboxInstance, type SandboxIsolationLevel, SandboxLatticeManager, type SandboxManagerProtocol, type SandboxProvider, type SandboxShellService, SandboxSkillStore, type SandboxSkillStoreOptions, type SandboxVolumeDefinition, type ScheduleLattice, ScheduleLatticeManager, type SchedulerMiddlewareOptions, SemanticMetricsClient, type SkillLattice, SkillLatticeManager, type SkillMeta, type SkillResource, SqlDatabaseManager, type StateAndStore, StateBackend, StoreBackend, type StoreLattice, StoreLatticeManager, type StoreType, type StoreTypeMap, TOOL_RESULT_TOKEN_LIMIT, TRUNCATION_GUIDANCE, type TableInfo, type TableSchema, type TaskEvent, type TaskListStore, type TaskSpec, TaskStatus, type TaskUpdatable, TeamAgentGraphBuilder, type TeamConfig, type TeamMiddlewareOptions, type TeamTask, type TeammateSpec, type TeammateToolsOptions, type ThreadBuffer, type ThreadBufferConfig, type ThreadBusyEvent, type ThreadIdleEvent, type ThreadInfo, type ThreadQueueConfig, type ThreadState, ThreadStatus, type ThreadStatusChangedEvent, type ToolDefinition, type ToolLattice, ToolLatticeManager, type TopologyEdge, type UnknownToolHandlerConfig, type VectorStoreLatticeInterface, VectorStoreLatticeManager, VolumeFilesystem, type VolumeFsClient, type WriteResult, agentInstanceManager, agentLatticeManager, buildGrepResultsDict, buildNamedVolumeName, buildSandboxMetadataEnv, buildSkillFile, checkEmptyContent, clearEncryptionKeyCache, computeSandboxName, configureStores, createAgentTeam, createExecuteSqlQueryTool, createFileData, createInfoSqlTool, createListMetricsDataSourcesTool, createListMetricsServersTool, createListTablesSqlTool, createModelSelectorMiddleware, createProcessingAgent, createQueryCheckerSqlTool, createQueryMetricDefinitionTool, createQueryMetricsListTool, createQuerySemanticMetricDataTool, createQuerySqlTool, createQueryTableDefinitionTool, createQueryTablesListTool, createSandboxProvider, createSchedulerMiddleware, createTeamMiddleware, createTeammateTools, createUnknownToolHandlerMiddleware, createWidgetMiddleware, decrypt, describeCronExpression, embeddingsLatticeManager, encrypt, ensureBuiltinAgentsForTenant, eventBus, eventBus as eventBusDefault, extractFetcherError, fileDataToString, formatContentWithLineNumbers, formatGrepMatches, formatGrepResults, formatReadResponse, getAgentClient, getAgentConfig, getAllAgentConfigs, getAllBuiltInSkillMetas, getAllToolDefinitions, getBindingRegistry, getBuiltInSkillContent, getBuiltInSkillMeta, getBuiltInSkillNames, getCheckpointSaver, getChunkBuffer, getEmbeddingsClient, getEmbeddingsLattice, getEncryptionKey, getLoggerLattice, getModelLattice, getNextCronTime, getQueueLattice, getSandBoxManager, getScheduleLattice, getStoreLattice, getToolClient, getToolDefinition, getToolLattice, getVectorStoreClient, getVectorStoreLattice, globSearchFiles, grepMatchesFromFiles, grepSearchFiles, hasChunkBuffer, isBuiltInSkill, isUsingDefaultKey, isValidCronExpression, isValidSandboxName, isValidSkillName, loggerLatticeManager, mcpManager, metricsServerManager, modelLatticeManager, normalizeSandboxName, parseCronExpression, parseSkillFrontmatter, performStringReplacement, queueLatticeManager, registerAgentLattice, registerAgentLatticeWithTenant, registerAgentLattices, registerCheckpointSaver, registerChunkBuffer, registerEmbeddingsLattice, registerExistingTool, registerLoggerLattice, registerModelLattice, registerQueueLattice, registerScheduleLattice, registerStoreLattice, registerTeammateAgent, registerToolLattice, registerVectorStoreLattice, sandboxLatticeManager, sanitizeToolCallId, scheduleLatticeManager, setBindingRegistry, skillLatticeManager, sqlDatabaseManager, storeLatticeManager, toolLatticeManager, truncateIfTooLong, unregisterTeammateAgent, updateFileData, validateAgentInput, validateEncryptionKey, validatePath, validateSkillName, validateToolInput, vectorStoreLatticeManager };
|