@electric-ax/agents-server 0.4.6 → 0.4.9

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/index.d.cts CHANGED
@@ -187,7 +187,7 @@ import * as drizzle_orm_pg_core238 from "drizzle-orm/pg-core";
187
187
  import * as drizzle_orm_pg_core239 from "drizzle-orm/pg-core";
188
188
  import * as drizzle_orm73 from "drizzle-orm";
189
189
  import * as drizzle_orm74 from "drizzle-orm";
190
- import { EntityTags, WebhookNotification, WebhookSignatureVerifierConfig } from "@electric-ax/agents-runtime";
190
+ import { EntityTags, EventSourceBucket, EventSourceContract, EventSourceContract as EventSourceContract$1, EventSourceFilter, EventSourceSubscription, EventSourceSubscription as EventSourceSubscription$1, EventSourceSubscriptionInput, SubscriptionLifetime, WebhookNotification, WebhookSignatureVerifierConfig } from "@electric-ax/agents-runtime";
191
191
  import "@sinclair/typebox";
192
192
  import { MaybePromise } from "@durable-streams/client";
193
193
  import { AutoRouterType, IRequest } from "itty-router";
@@ -3226,7 +3226,10 @@ interface Principal {
3226
3226
  type WakeNotification = WebhookNotification;
3227
3227
  type RequestPrincipal = Principal;
3228
3228
  type AuthenticateRequest = (request: Request) => Promise<Principal | null> | Principal | null;
3229
- type EntityStatus = `spawning` | `running` | `idle` | `stopped`;
3229
+ type EntityStatus = `spawning` | `running` | `idle` | `paused` | `stopping` | `stopped` | `killed`;
3230
+ declare const ENTITY_SIGNALS: readonly ["SIGINT", "SIGHUP", "SIGTERM", "SIGKILL", "SIGSTOP", "SIGCONT", "SIGUSR"];
3231
+ type EntitySignal = (typeof ENTITY_SIGNALS)[number];
3232
+ declare function assertEntityStatus(s: string): EntityStatus;
3230
3233
  type DispatchTarget = {
3231
3234
  type: `webhook`;
3232
3235
  url: string;
@@ -3353,6 +3356,10 @@ interface ConsumerClaim {
3353
3356
  acked_streams?: Array<SourceStreamOffset>;
3354
3357
  updated_at: string;
3355
3358
  }
3359
+ declare function assertEntitySignal(s: string): EntitySignal;
3360
+ declare function isTerminalEntityStatus(status: EntityStatus): boolean;
3361
+ declare function rejectsNormalWrites(status: EntityStatus): boolean;
3362
+ declare function expectedSignalStatus(status: EntityStatus, signal: EntitySignal): EntityStatus;
3356
3363
  interface ElectricAgentsEntity {
3357
3364
  url: string;
3358
3365
  type: string;
@@ -3375,7 +3382,26 @@ interface ElectricAgentsEntity {
3375
3382
  updated_at: number;
3376
3383
  }
3377
3384
  /** Public-facing entity — internal fields stripped. Standalone type so new internal fields don't silently leak. */
3378
-
3385
+ interface PublicElectricAgentsEntity {
3386
+ url: string;
3387
+ type: string;
3388
+ status: EntityStatus;
3389
+ streams: {
3390
+ main: string;
3391
+ error: string;
3392
+ };
3393
+ dispatch_policy?: DispatchPolicy;
3394
+ tags: Record<string, string>;
3395
+ spawn_args?: Record<string, unknown>;
3396
+ parent?: string;
3397
+ created_by?: string;
3398
+ created_at: number;
3399
+ updated_at: number;
3400
+ }
3401
+ /** Entity row as stored in Postgres / returned by Electric shapes (no derived `streams` field). */
3402
+ type ElectricAgentsEntityRow = Omit<PublicElectricAgentsEntity, `streams`>;
3403
+ /** Strip internal fields (write_token, subscription_id) from an entity. */
3404
+ declare function toPublicEntity(entity: ElectricAgentsEntity): PublicElectricAgentsEntity;
3379
3405
  interface ElectricAgentsEntityType {
3380
3406
  name: string;
3381
3407
  description: string;
@@ -3415,6 +3441,7 @@ interface TypedSpawnRequest {
3415
3441
  debounceMs?: number;
3416
3442
  timeoutMs?: number;
3417
3443
  includeResponse?: boolean;
3444
+ manifestKey?: string;
3418
3445
  };
3419
3446
  }
3420
3447
  interface SendRequest {
@@ -3425,9 +3452,27 @@ interface SendRequest {
3425
3452
  mode?: `immediate` | `queued` | `paused` | `steer`;
3426
3453
  position?: string;
3427
3454
  }
3455
+ interface SignalRequest {
3456
+ signal: EntitySignal;
3457
+ reason?: string;
3458
+ payload?: unknown;
3459
+ }
3460
+ interface SignalResponse {
3461
+ url: string;
3462
+ signal: EntitySignal;
3463
+ previous_state: EntityStatus;
3464
+ new_state: EntityStatus;
3465
+ created_at: number;
3466
+ txid: number;
3467
+ }
3428
3468
  interface SetTagRequest {
3429
3469
  value: string;
3430
3470
  }
3471
+ interface EntityListFilter {
3472
+ type?: string;
3473
+ status?: EntityStatus;
3474
+ created_by?: string;
3475
+ }
3431
3476
 
3432
3477
  //#endregion
3433
3478
  //#region src/entity-registry.d.ts
@@ -3559,7 +3604,8 @@ declare class PostgresRegistry {
3559
3604
  total: number;
3560
3605
  }>;
3561
3606
  updateStatus(entityUrl: string, status: EntityStatus): Promise<void>;
3562
- updateStatusWithTxid(entityUrl: string, status: EntityStatus): Promise<number>;
3607
+ updateStatusWithTxid(entityUrl: string, status: EntityStatus): Promise<number | null>;
3608
+ touchEntityWithTxid(entityUrl: string): Promise<number | null>;
3563
3609
  setEntityTag(url: string, key: string, value: string): Promise<{
3564
3610
  entity: ElectricAgentsEntity | null;
3565
3611
  changed: boolean;
@@ -4160,6 +4206,18 @@ declare class EntityManager {
4160
4206
  }): Promise<{
4161
4207
  txid: string;
4162
4208
  }>;
4209
+ upsertEventSourceSubscription(entityUrl: string, req: {
4210
+ subscription: EventSourceSubscription$1;
4211
+ manifest: Record<string, unknown>;
4212
+ }): Promise<{
4213
+ txid: string;
4214
+ subscription: EventSourceSubscription$1;
4215
+ }>;
4216
+ deleteEventSourceSubscription(entityUrl: string, req: {
4217
+ id: string;
4218
+ }): Promise<{
4219
+ txid: string;
4220
+ }>;
4163
4221
  /**
4164
4222
  * Register a wake subscription from a subscriber to a source entity.
4165
4223
  */
@@ -4193,9 +4251,12 @@ declare class EntityManager {
4193
4251
  */
4194
4252
  private extractRunResponse;
4195
4253
  private buildWakeMessage;
4254
+ signal(entityUrl: string, req: SignalRequest): Promise<SignalResponse>;
4196
4255
  kill(entityUrl: string): Promise<{
4197
4256
  txid: number;
4198
4257
  }>;
4258
+ private serverHandlingForSignal;
4259
+ private appendSignalEvent;
4199
4260
  validateWriteEvent(entity: ElectricAgentsEntity, event: Record<string, unknown>): Promise<{
4200
4261
  code: string;
4201
4262
  message: string;
@@ -4406,6 +4467,10 @@ declare function webhookSigningMetadata(signer: WebhookSigner, streamRootUrl: st
4406
4467
 
4407
4468
  //#endregion
4408
4469
  //#region src/routing/context.d.ts
4470
+ interface EventSourceCatalog {
4471
+ listEventSources: () => Array<EventSourceContract$1> | Promise<Array<EventSourceContract$1>>;
4472
+ getEventSource: (sourceKey: string) => EventSourceContract$1 | undefined | Promise<EventSourceContract$1 | undefined>;
4473
+ }
4409
4474
  /**
4410
4475
  * Per-request tenant context passed through every router and handler.
4411
4476
  *
@@ -4432,6 +4497,8 @@ interface TenantContext {
4432
4497
  streamClient: StreamClient;
4433
4498
  runtime: ElectricAgentsTenantRuntime;
4434
4499
  entityBridgeManager: EntityBridgeCoordinator;
4500
+ eventSources?: EventSourceCatalog;
4501
+ ensureEventSourceWakeSource?: (sourceUrl: string) => Promise<void> | void;
4435
4502
  isShuttingDown: () => boolean;
4436
4503
  }
4437
4504
 
@@ -4451,4 +4518,4 @@ declare class UnregisteredTenantError extends Error {
4451
4518
  declare function isUnregisteredTenantError(error: unknown): error is UnregisteredTenantError;
4452
4519
 
4453
4520
  //#endregion
4454
- export { AgentsHost, AgentsHostOptions, AgentsHostTenantConfig, AgentsHostTenantRuntime, AuthenticateRequest, ConsumerClaim, DEFAULT_TENANT_ID, DispatchPolicy, DispatchTarget, DrizzleDB, DurableStreamsBearerProvider, DurableStreamsRoutingAdapter, DurableStreamsRoutingInput, Ed25519WebhookSignerOptions, ElectricAgentsRunner, ElectricAgentsUser, EntityBridgeCoordinator, EntityDispatchState, GlobalRoutes, PgClient, Principal, PrincipalKind, PublicWakeNotification, RegisterRunnerRequest, RequestPrincipal, RunnerAdminStatus, RunnerHeartbeatRequest, RunnerKind, RunnerLiveness, SourceStreamOffset, StreamClient, StreamClientOptions, SubscriptionClaimResponse, SubscriptionCreateInput, SubscriptionResponse, SubscriptionStreamInfo, TenantContext, UnregisteredTenantError, WakeNotificationRow, WebhookJwks, WebhookPublicJwk, WebhookSigner, WebhookSigningKeyInput, WebhookSigningMetadata, createDb, createEd25519WebhookSigner, getDefaultWebhookSigner, globalRouter, isUnregisteredTenantError, pathPrefixedSingleTenantDurableStreamsRoutingAdapter, runMigrations, streamRootDurableStreamsRoutingAdapter, tenantRootDurableStreamsRoutingAdapter, webhookSigningMetadata };
4521
+ export { AgentsHost, AgentsHostOptions, AgentsHostTenantConfig, AgentsHostTenantRuntime, AuthenticateRequest, ConsumerClaim, DEFAULT_TENANT_ID, DispatchPolicy, DispatchTarget, DrizzleDB, DurableStreamsBearerProvider, DurableStreamsRoutingAdapter, DurableStreamsRoutingInput, Ed25519WebhookSignerOptions, ElectricAgentsEntity, ElectricAgentsEntityRow, ElectricAgentsEntityType, ElectricAgentsRunner, ElectricAgentsUser, EntityBridgeCoordinator, EntityDispatchState, EntityListFilter, EntitySignal, EntityStatus, EventSourceBucket, EventSourceCatalog, EventSourceContract, EventSourceFilter, EventSourceSubscription, EventSourceSubscriptionInput, GlobalRoutes, PgClient, Principal, PrincipalKind, PublicElectricAgentsEntity, PublicWakeNotification, RegisterEntityTypeRequest, RegisterRunnerRequest, RequestPrincipal, RunnerAdminStatus, RunnerHeartbeatRequest, RunnerKind, RunnerLiveness, SendRequest, SignalRequest, SignalResponse, SourceStreamOffset, StreamClient, StreamClientOptions, SubscriptionClaimResponse, SubscriptionCreateInput, SubscriptionLifetime, SubscriptionResponse, SubscriptionStreamInfo, TenantContext, TypedSpawnRequest, UnregisteredTenantError, WakeNotificationRow, WebhookJwks, WebhookPublicJwk, WebhookSigner, WebhookSigningKeyInput, WebhookSigningMetadata, assertEntitySignal, assertEntityStatus, createDb, createEd25519WebhookSigner, expectedSignalStatus, getDefaultWebhookSigner, globalRouter, isTerminalEntityStatus, isUnregisteredTenantError, pathPrefixedSingleTenantDurableStreamsRoutingAdapter, rejectsNormalWrites, runMigrations, streamRootDurableStreamsRoutingAdapter, tenantRootDurableStreamsRoutingAdapter, toPublicEntity, webhookSigningMetadata };
package/dist/index.d.ts CHANGED
@@ -189,7 +189,7 @@ import * as drizzle_orm_pg_core237 from "drizzle-orm/pg-core";
189
189
  import * as drizzle_orm_pg_core238 from "drizzle-orm/pg-core";
190
190
  import * as drizzle_orm_pg_core239 from "drizzle-orm/pg-core";
191
191
  import { JsonWebKey, KeyObject } from "node:crypto";
192
- import { EntityTags, WebhookNotification, WebhookSignatureVerifierConfig } from "@electric-ax/agents-runtime";
192
+ import { EntityTags, EventSourceBucket, EventSourceContract, EventSourceContract as EventSourceContract$1, EventSourceFilter, EventSourceSubscription, EventSourceSubscription as EventSourceSubscription$1, EventSourceSubscriptionInput, SubscriptionLifetime, WebhookNotification, WebhookSignatureVerifierConfig } from "@electric-ax/agents-runtime";
193
193
  import { MaybePromise } from "@durable-streams/client";
194
194
  import "@sinclair/typebox";
195
195
  import { AutoRouterType, IRequest } from "itty-router";
@@ -3227,7 +3227,10 @@ interface Principal {
3227
3227
  type WakeNotification = WebhookNotification;
3228
3228
  type RequestPrincipal = Principal;
3229
3229
  type AuthenticateRequest = (request: Request) => Promise<Principal | null> | Principal | null;
3230
- type EntityStatus = `spawning` | `running` | `idle` | `stopped`;
3230
+ type EntityStatus = `spawning` | `running` | `idle` | `paused` | `stopping` | `stopped` | `killed`;
3231
+ declare const ENTITY_SIGNALS: readonly ["SIGINT", "SIGHUP", "SIGTERM", "SIGKILL", "SIGSTOP", "SIGCONT", "SIGUSR"];
3232
+ type EntitySignal = (typeof ENTITY_SIGNALS)[number];
3233
+ declare function assertEntityStatus(s: string): EntityStatus;
3231
3234
  type DispatchTarget = {
3232
3235
  type: `webhook`;
3233
3236
  url: string;
@@ -3354,6 +3357,10 @@ interface ConsumerClaim {
3354
3357
  acked_streams?: Array<SourceStreamOffset>;
3355
3358
  updated_at: string;
3356
3359
  }
3360
+ declare function assertEntitySignal(s: string): EntitySignal;
3361
+ declare function isTerminalEntityStatus(status: EntityStatus): boolean;
3362
+ declare function rejectsNormalWrites(status: EntityStatus): boolean;
3363
+ declare function expectedSignalStatus(status: EntityStatus, signal: EntitySignal): EntityStatus;
3357
3364
  interface ElectricAgentsEntity {
3358
3365
  url: string;
3359
3366
  type: string;
@@ -3376,7 +3383,26 @@ interface ElectricAgentsEntity {
3376
3383
  updated_at: number;
3377
3384
  }
3378
3385
  /** Public-facing entity — internal fields stripped. Standalone type so new internal fields don't silently leak. */
3379
-
3386
+ interface PublicElectricAgentsEntity {
3387
+ url: string;
3388
+ type: string;
3389
+ status: EntityStatus;
3390
+ streams: {
3391
+ main: string;
3392
+ error: string;
3393
+ };
3394
+ dispatch_policy?: DispatchPolicy;
3395
+ tags: Record<string, string>;
3396
+ spawn_args?: Record<string, unknown>;
3397
+ parent?: string;
3398
+ created_by?: string;
3399
+ created_at: number;
3400
+ updated_at: number;
3401
+ }
3402
+ /** Entity row as stored in Postgres / returned by Electric shapes (no derived `streams` field). */
3403
+ type ElectricAgentsEntityRow = Omit<PublicElectricAgentsEntity, `streams`>;
3404
+ /** Strip internal fields (write_token, subscription_id) from an entity. */
3405
+ declare function toPublicEntity(entity: ElectricAgentsEntity): PublicElectricAgentsEntity;
3380
3406
  interface ElectricAgentsEntityType {
3381
3407
  name: string;
3382
3408
  description: string;
@@ -3416,6 +3442,7 @@ interface TypedSpawnRequest {
3416
3442
  debounceMs?: number;
3417
3443
  timeoutMs?: number;
3418
3444
  includeResponse?: boolean;
3445
+ manifestKey?: string;
3419
3446
  };
3420
3447
  }
3421
3448
  interface SendRequest {
@@ -3426,9 +3453,27 @@ interface SendRequest {
3426
3453
  mode?: `immediate` | `queued` | `paused` | `steer`;
3427
3454
  position?: string;
3428
3455
  }
3456
+ interface SignalRequest {
3457
+ signal: EntitySignal;
3458
+ reason?: string;
3459
+ payload?: unknown;
3460
+ }
3461
+ interface SignalResponse {
3462
+ url: string;
3463
+ signal: EntitySignal;
3464
+ previous_state: EntityStatus;
3465
+ new_state: EntityStatus;
3466
+ created_at: number;
3467
+ txid: number;
3468
+ }
3429
3469
  interface SetTagRequest {
3430
3470
  value: string;
3431
3471
  }
3472
+ interface EntityListFilter {
3473
+ type?: string;
3474
+ status?: EntityStatus;
3475
+ created_by?: string;
3476
+ }
3432
3477
 
3433
3478
  //#endregion
3434
3479
  //#region src/entity-registry.d.ts
@@ -3560,7 +3605,8 @@ declare class PostgresRegistry {
3560
3605
  total: number;
3561
3606
  }>;
3562
3607
  updateStatus(entityUrl: string, status: EntityStatus): Promise<void>;
3563
- updateStatusWithTxid(entityUrl: string, status: EntityStatus): Promise<number>;
3608
+ updateStatusWithTxid(entityUrl: string, status: EntityStatus): Promise<number | null>;
3609
+ touchEntityWithTxid(entityUrl: string): Promise<number | null>;
3564
3610
  setEntityTag(url: string, key: string, value: string): Promise<{
3565
3611
  entity: ElectricAgentsEntity | null;
3566
3612
  changed: boolean;
@@ -4161,6 +4207,18 @@ declare class EntityManager {
4161
4207
  }): Promise<{
4162
4208
  txid: string;
4163
4209
  }>;
4210
+ upsertEventSourceSubscription(entityUrl: string, req: {
4211
+ subscription: EventSourceSubscription$1;
4212
+ manifest: Record<string, unknown>;
4213
+ }): Promise<{
4214
+ txid: string;
4215
+ subscription: EventSourceSubscription$1;
4216
+ }>;
4217
+ deleteEventSourceSubscription(entityUrl: string, req: {
4218
+ id: string;
4219
+ }): Promise<{
4220
+ txid: string;
4221
+ }>;
4164
4222
  /**
4165
4223
  * Register a wake subscription from a subscriber to a source entity.
4166
4224
  */
@@ -4194,9 +4252,12 @@ declare class EntityManager {
4194
4252
  */
4195
4253
  private extractRunResponse;
4196
4254
  private buildWakeMessage;
4255
+ signal(entityUrl: string, req: SignalRequest): Promise<SignalResponse>;
4197
4256
  kill(entityUrl: string): Promise<{
4198
4257
  txid: number;
4199
4258
  }>;
4259
+ private serverHandlingForSignal;
4260
+ private appendSignalEvent;
4200
4261
  validateWriteEvent(entity: ElectricAgentsEntity, event: Record<string, unknown>): Promise<{
4201
4262
  code: string;
4202
4263
  message: string;
@@ -4407,6 +4468,10 @@ declare function webhookSigningMetadata(signer: WebhookSigner, streamRootUrl: st
4407
4468
 
4408
4469
  //#endregion
4409
4470
  //#region src/routing/context.d.ts
4471
+ interface EventSourceCatalog {
4472
+ listEventSources: () => Array<EventSourceContract$1> | Promise<Array<EventSourceContract$1>>;
4473
+ getEventSource: (sourceKey: string) => EventSourceContract$1 | undefined | Promise<EventSourceContract$1 | undefined>;
4474
+ }
4410
4475
  /**
4411
4476
  * Per-request tenant context passed through every router and handler.
4412
4477
  *
@@ -4433,6 +4498,8 @@ interface TenantContext {
4433
4498
  streamClient: StreamClient;
4434
4499
  runtime: ElectricAgentsTenantRuntime;
4435
4500
  entityBridgeManager: EntityBridgeCoordinator;
4501
+ eventSources?: EventSourceCatalog;
4502
+ ensureEventSourceWakeSource?: (sourceUrl: string) => Promise<void> | void;
4436
4503
  isShuttingDown: () => boolean;
4437
4504
  }
4438
4505
 
@@ -4452,4 +4519,4 @@ declare class UnregisteredTenantError extends Error {
4452
4519
  declare function isUnregisteredTenantError(error: unknown): error is UnregisteredTenantError;
4453
4520
 
4454
4521
  //#endregion
4455
- export { AgentsHost, AgentsHostOptions, AgentsHostTenantConfig, AgentsHostTenantRuntime, AuthenticateRequest, ConsumerClaim, DEFAULT_TENANT_ID, DispatchPolicy, DispatchTarget, DrizzleDB, DurableStreamsBearerProvider, DurableStreamsRoutingAdapter, DurableStreamsRoutingInput, Ed25519WebhookSignerOptions, ElectricAgentsRunner, ElectricAgentsUser, EntityBridgeCoordinator, EntityDispatchState, GlobalRoutes, PgClient, Principal, PrincipalKind, PublicWakeNotification, RegisterRunnerRequest, RequestPrincipal, RunnerAdminStatus, RunnerHeartbeatRequest, RunnerKind, RunnerLiveness, SourceStreamOffset, StreamClient, StreamClientOptions, SubscriptionClaimResponse, SubscriptionCreateInput, SubscriptionResponse, SubscriptionStreamInfo, TenantContext, UnregisteredTenantError, WakeNotificationRow, WebhookJwks, WebhookPublicJwk, WebhookSigner, WebhookSigningKeyInput, WebhookSigningMetadata, createDb, createEd25519WebhookSigner, getDefaultWebhookSigner, globalRouter, isUnregisteredTenantError, pathPrefixedSingleTenantDurableStreamsRoutingAdapter, runMigrations, streamRootDurableStreamsRoutingAdapter, tenantRootDurableStreamsRoutingAdapter, webhookSigningMetadata };
4522
+ export { AgentsHost, AgentsHostOptions, AgentsHostTenantConfig, AgentsHostTenantRuntime, AuthenticateRequest, ConsumerClaim, DEFAULT_TENANT_ID, DispatchPolicy, DispatchTarget, DrizzleDB, DurableStreamsBearerProvider, DurableStreamsRoutingAdapter, DurableStreamsRoutingInput, Ed25519WebhookSignerOptions, ElectricAgentsEntity, ElectricAgentsEntityRow, ElectricAgentsEntityType, ElectricAgentsRunner, ElectricAgentsUser, EntityBridgeCoordinator, EntityDispatchState, EntityListFilter, EntitySignal, EntityStatus, EventSourceBucket, EventSourceCatalog, EventSourceContract, EventSourceFilter, EventSourceSubscription, EventSourceSubscriptionInput, GlobalRoutes, PgClient, Principal, PrincipalKind, PublicElectricAgentsEntity, PublicWakeNotification, RegisterEntityTypeRequest, RegisterRunnerRequest, RequestPrincipal, RunnerAdminStatus, RunnerHeartbeatRequest, RunnerKind, RunnerLiveness, SendRequest, SignalRequest, SignalResponse, SourceStreamOffset, StreamClient, StreamClientOptions, SubscriptionClaimResponse, SubscriptionCreateInput, SubscriptionLifetime, SubscriptionResponse, SubscriptionStreamInfo, TenantContext, TypedSpawnRequest, UnregisteredTenantError, WakeNotificationRow, WebhookJwks, WebhookPublicJwk, WebhookSigner, WebhookSigningKeyInput, WebhookSigningMetadata, assertEntitySignal, assertEntityStatus, createDb, createEd25519WebhookSigner, expectedSignalStatus, getDefaultWebhookSigner, globalRouter, isTerminalEntityStatus, isUnregisteredTenantError, pathPrefixedSingleTenantDurableStreamsRoutingAdapter, rejectsNormalWrites, runMigrations, streamRootDurableStreamsRoutingAdapter, tenantRootDurableStreamsRoutingAdapter, toPublicEntity, webhookSigningMetadata };