@keystrokehq/hosting 0.1.10 → 0.1.12

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.cjs CHANGED
@@ -21,6 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
+ let node_crypto = require("node:crypto");
24
25
  let dockerode = require("dockerode");
25
26
  dockerode = __toESM(dockerode, 1);
26
27
  let node_fs_promises = require("node:fs/promises");
@@ -4831,6 +4832,7 @@ const INFRA_SYSTEM_SLUGS = [
4831
4832
  "health",
4832
4833
  "healthcheck",
4833
4834
  "healthz",
4835
+ "hook-resume",
4834
4836
  "hooks",
4835
4837
  "internal",
4836
4838
  "item",
@@ -4996,14 +4998,14 @@ const OrganizationUserRoleSchema = _enum([
4996
4998
  "admin",
4997
4999
  "builder"
4998
5000
  ]);
4999
- const isoDateTime$5 = string().datetime();
5001
+ const isoDateTime$7 = string().datetime();
5000
5002
  const OrganizationSchema = object({
5001
5003
  id: string(),
5002
5004
  name: string(),
5003
5005
  slug: OrganizationSlugSchema,
5004
5006
  verified: boolean(),
5005
- createdAt: isoDateTime$5,
5006
- updatedAt: isoDateTime$5
5007
+ createdAt: isoDateTime$7,
5008
+ updatedAt: isoDateTime$7
5007
5009
  });
5008
5010
  const ProjectSchema = object({
5009
5011
  id: string(),
@@ -5015,8 +5017,8 @@ const ProjectSchema = object({
5015
5017
  baseUrl: string().nullable(),
5016
5018
  runtimeId: string().nullable(),
5017
5019
  lastError: string().nullable(),
5018
- createdAt: isoDateTime$5,
5019
- updatedAt: isoDateTime$5
5020
+ createdAt: isoDateTime$7,
5021
+ updatedAt: isoDateTime$7
5020
5022
  });
5021
5023
  object({
5022
5024
  organization: OrganizationSchema,
@@ -5036,7 +5038,7 @@ const ProjectListMetricsSchema = object({
5036
5038
  workflowCount: number$1(),
5037
5039
  skillCount: number$1(),
5038
5040
  credentialCount: number$1(),
5039
- lastDeploymentAt: isoDateTime$5.nullable()
5041
+ lastDeploymentAt: isoDateTime$7.nullable()
5040
5042
  });
5041
5043
  record(string(), ProjectListMetricsSchema);
5042
5044
  object({
@@ -5055,6 +5057,14 @@ const AppSlugSchema = ProjectSlugSchema;
5055
5057
  function resolveExplicitPublicPlatformOrigin(env = process.env) {
5056
5058
  return env.PUBLIC_PLATFORM_URL?.replace(/\/$/, "") || void 0;
5057
5059
  }
5060
+ function isValidIanaTimezone(value) {
5061
+ try {
5062
+ Intl.DateTimeFormat(void 0, { timeZone: value });
5063
+ return true;
5064
+ } catch {
5065
+ return false;
5066
+ }
5067
+ }
5058
5068
  /** How a credential instance is stored (`credential_instances.auth_kind`). */
5059
5069
  const CredentialAuthKindSchema = _enum([
5060
5070
  "api_key",
@@ -5312,6 +5322,7 @@ const storedRouteManifestEntryV2Schema = discriminatedUnion("kind", [
5312
5322
  name: requiredDisplayTextSchema,
5313
5323
  description: requiredDisplayTextSchema,
5314
5324
  model: string(),
5325
+ compactionModel: string().optional(),
5315
5326
  systemPrompt: string(),
5316
5327
  toolCount: number$1().int().nonnegative(),
5317
5328
  credentialCount: number$1().int().nonnegative(),
@@ -5345,7 +5356,9 @@ const storedRouteManifestEntryV2Schema = discriminatedUnion("kind", [
5345
5356
  /** Deterministic AST control-flow skeleton (deploy-time producer). */
5346
5357
  flowGraph: WorkflowCanvasGraphSchema.optional(),
5347
5358
  /** sha256 of the workflow source the `flowGraph` was produced from (staleness). */
5348
- flowGraphSourceHash: string().optional()
5359
+ flowGraphSourceHash: string().optional(),
5360
+ /** sha256 of `JSON.stringify(flowGraph)` — baked at build so canvas polls skip re-hashing. */
5361
+ flowGraphHash: string().optional()
5349
5362
  }),
5350
5363
  object({
5351
5364
  kind: literal("trigger-webhook"),
@@ -5381,6 +5394,8 @@ const storedRouteManifestEntryV2Schema = discriminatedUnion("kind", [
5381
5394
  moduleFile: string(),
5382
5395
  sourceHash: string().optional(),
5383
5396
  schedule: string(),
5397
+ /** Static cron payload from `defineCronSource({ payload })` — omitted when the source has none. */
5398
+ payload: unknown().optional(),
5384
5399
  name: requiredDisplayTextSchema,
5385
5400
  description: requiredDisplayTextSchema
5386
5401
  })
@@ -5391,6 +5406,171 @@ object({
5391
5406
  skills: array(StoredRouteManifestSkillSchema).default([]),
5392
5407
  integrations: array(string()).optional()
5393
5408
  });
5409
+ const isoDateTime$6 = string().datetime();
5410
+ const subscriptionStatusSchema = _enum([
5411
+ "none",
5412
+ "trialing",
5413
+ "active",
5414
+ "past_due",
5415
+ "canceled"
5416
+ ]);
5417
+ const CreditPackSchema = object({
5418
+ id: string(),
5419
+ usd: number$1(),
5420
+ microCredits: number$1(),
5421
+ label: string()
5422
+ });
5423
+ const AutoTopupSummarySchema = object({
5424
+ enabled: boolean(),
5425
+ thresholdMicroCredits: number$1().nullable(),
5426
+ amountMicroCredits: number$1().nullable(),
5427
+ /** A saved payment method exists to charge off-session. */
5428
+ hasPaymentMethod: boolean(),
5429
+ /** A top-up invoice payment is in flight. */
5430
+ pending: boolean()
5431
+ });
5432
+ /**
5433
+ * The plan's resolved limits. Storage overage is billed from the wallet's
5434
+ * pushed-down `includedStorageGb`; concurrency, per-pass run timeouts, and
5435
+ * API/MCP rate limits are enforced from the wallet (timeouts/concurrency) or
5436
+ * plan preset (rate limits). Log retention is configured but not pruned yet.
5437
+ */
5438
+ const PlanLimitsSchema = object({
5439
+ includedStorageGb: number$1(),
5440
+ concurrencyLimit: number$1(),
5441
+ agentTimeoutMs: number$1(),
5442
+ workflowTimeoutMs: number$1(),
5443
+ pollTimeoutMs: number$1(),
5444
+ /** Configured retention window; pruning not implemented yet. */
5445
+ logRetentionDays: number$1(),
5446
+ apiRateLimitCapacity: number$1(),
5447
+ apiRateLimitRefillPerSec: number$1(),
5448
+ mcpRateLimitCapacity: number$1(),
5449
+ mcpRateLimitRefillPerSec: number$1()
5450
+ });
5451
+ object({
5452
+ planKey: string(),
5453
+ subscriptionStatus: subscriptionStatusSchema,
5454
+ planCreditMicroCredits: number$1(),
5455
+ prepaidCreditMicroCredits: number$1(),
5456
+ periodStart: isoDateTime$6.nullable(),
5457
+ periodEnd: isoDateTime$6.nullable(),
5458
+ autoTopup: AutoTopupSummarySchema,
5459
+ creditPacks: array(CreditPackSchema),
5460
+ limits: PlanLimitsSchema
5461
+ });
5462
+ const BillingUsageMeterSchema = object({
5463
+ /** Meter key (`llm`, `vm_second`, …); null groups uncategorized rows. */
5464
+ meterKey: string().nullable(),
5465
+ /** Charged this period, µc. */
5466
+ microCredits: number$1(),
5467
+ /** Tracked-but-not-charged usage (e.g. BYOK LLM calls), display USD. */
5468
+ unchargedUsd: number$1()
5469
+ });
5470
+ object({
5471
+ periodStart: isoDateTime$6.nullable(),
5472
+ periodEnd: isoDateTime$6.nullable(),
5473
+ totalMicroCredits: number$1(),
5474
+ byMeter: array(BillingUsageMeterSchema)
5475
+ });
5476
+ const billingLedgerEntryTypeSchema = _enum([
5477
+ "grant_plan",
5478
+ "grant_prepaid",
5479
+ "expire_plan",
5480
+ "adjustment"
5481
+ ]);
5482
+ object({
5483
+ entries: array(object({
5484
+ id: string(),
5485
+ entryType: billingLedgerEntryTypeSchema,
5486
+ label: string(),
5487
+ /** Signed: positive grants, negative expirations/adjustments. */
5488
+ microCredits: number$1(),
5489
+ bucket: _enum(["plan", "prepaid"]).nullable(),
5490
+ /** Stripe invoice behind the entry, when there is one — powers "View invoice". */
5491
+ stripeInvoiceId: string().nullable(),
5492
+ createdAt: isoDateTime$6
5493
+ })),
5494
+ /** Set only when the latest payment failure is newer than the latest successful payment. */
5495
+ lastPaymentFailureAt: isoDateTime$6.nullable()
5496
+ });
5497
+ object({
5498
+ /** Web-app path to land on after Checkout (must be a path, not a URL). */
5499
+ returnPath: string().startsWith("/").max(512).optional() });
5500
+ object({
5501
+ packId: string(),
5502
+ returnPath: string().startsWith("/").max(512).optional()
5503
+ });
5504
+ object({ returnPath: string().startsWith("/").max(512).optional() });
5505
+ object({ url: string().url() });
5506
+ object({
5507
+ /** Hosted invoice page (view, download, receipt). */
5508
+ url: string().url(),
5509
+ /** Direct PDF download when Stripe provides one. */
5510
+ pdf: string().url().nullable()
5511
+ });
5512
+ object({
5513
+ /** Stripe Checkout Session id from the `session_id` success-URL param. */
5514
+ sessionId: string().min(1).max(255) });
5515
+ object({
5516
+ /**
5517
+ * `granted` — credits are in the wallet now; `processing` — payment not
5518
+ * complete yet, the webhook will finish it; `ignored` — not a confirmable
5519
+ * session for this org.
5520
+ */
5521
+ status: _enum([
5522
+ "granted",
5523
+ "processing",
5524
+ "ignored"
5525
+ ]),
5526
+ reason: string().optional()
5527
+ });
5528
+ object({
5529
+ enabled: boolean(),
5530
+ thresholdMicroCredits: number$1().int().positive().optional(),
5531
+ packId: string().optional()
5532
+ });
5533
+ const BillingUsageEventSourceSchema = _enum([
5534
+ "ai_gateway",
5535
+ "sandbox",
5536
+ "web_proxy",
5537
+ "storage",
5538
+ "dispatch",
5539
+ "poll"
5540
+ ]);
5541
+ const BillingUsageMeterKeySchema = _enum([
5542
+ "llm",
5543
+ "vm_second",
5544
+ "web_search",
5545
+ "web_fetch",
5546
+ "workflow_run",
5547
+ "agent_run",
5548
+ "poll_trigger",
5549
+ "tigris_storage"
5550
+ ]);
5551
+ const BillingUsageKeySourceSchema = _enum(["platform", "byok"]);
5552
+ const BillingUsageRunKindSchema = _enum(["agent", "workflow"]);
5553
+ object({ events: array(object({
5554
+ projectId: string().min(1).max(255).nullable().optional(),
5555
+ runId: string().min(1).max(255).nullable().optional(),
5556
+ runKind: BillingUsageRunKindSchema.nullable().optional(),
5557
+ source: BillingUsageEventSourceSchema,
5558
+ sourceEventId: string().min(1).max(512),
5559
+ meterKey: BillingUsageMeterKeySchema,
5560
+ quantity: number$1().finite().nonnegative(),
5561
+ unit: string().min(1).max(64),
5562
+ providerCostUsd: number$1().finite().nonnegative().nullable().optional(),
5563
+ keySource: BillingUsageKeySourceSchema.nullable().optional(),
5564
+ occurredAt: isoDateTime$6,
5565
+ metadata: record(string(), unknown()).nullable().optional()
5566
+ }).strict()).min(1).max(100) }).strict();
5567
+ object({
5568
+ accepted: number$1().int().nonnegative(),
5569
+ inserted: number$1().int().nonnegative(),
5570
+ duplicate: number$1().int().nonnegative(),
5571
+ settledLedgerId: string().nullable(),
5572
+ chargeMicroCredits: number$1().int().nonnegative()
5573
+ });
5394
5574
  /** Messaging platforms that support agent gateway bindings. */
5395
5575
  const ChannelPlatformKeySchema = _enum(["slack"]);
5396
5576
  const ChannelReactionSupportSchema = _enum([
@@ -5690,15 +5870,18 @@ object({
5690
5870
  integrationDescription: string().min(1),
5691
5871
  logo: string().url().nullable().optional(),
5692
5872
  authKind: AppAuthKindSchema,
5693
- oauthScopes: array(OAuthScopeOptionSchema),
5694
5873
  /** Where app metadata and execution are sourced (e.g. composio, custom). */
5695
5874
  source: AppSourceSchema,
5875
+ /** Endpoint URL for MCP, OpenAPI, or GraphQL custom apps. */
5876
+ url: string().url().nullable().optional(),
5877
+ /** True when the app has a non-empty credential field template. */
5878
+ hasCredentialFields: boolean().optional()
5879
+ }).extend({
5880
+ oauthScopes: array(OAuthScopeOptionSchema),
5696
5881
  /** Custom api_key apps — vault field template for connect UI and sync. */
5697
5882
  credentialFields: AppCredentialFieldsSchema.optional(),
5698
5883
  /** Composio auth scheme when credentialFields are present. */
5699
5884
  credentialScheme: AppCredentialSchemeSchema.optional(),
5700
- /** Endpoint URL for MCP, OpenAPI, or GraphQL custom apps. */
5701
- url: string().url().nullable().optional(),
5702
5885
  /** When present, the app supports agent gateway bindings (external channels). */
5703
5886
  gateway: AppGatewaySchema.optional()
5704
5887
  });
@@ -5820,7 +6003,11 @@ const AppCredentialConnectionKindSchema = _enum(["oauth", "manual"]);
5820
6003
  const OAuthPermissionModeSchema = _enum(["default", "restricted"]);
5821
6004
  const optionalTimestamp$1 = string().optional();
5822
6005
  const nullableOptionalTimestamp = string().nullable().optional();
5823
- object({
6006
+ /**
6007
+ * Summary row for the apps/credentials table and credential detail page.
6008
+ * Plaintext secrets are never returned — only masked `keyPreviews`.
6009
+ */
6010
+ const AppCredentialSummarySchema = object({
5824
6011
  id: string().min(1),
5825
6012
  appId: string().min(1),
5826
6013
  /** Stable per-scope identifier; pass to `--credential` to pin a specific instance. */
@@ -5911,7 +6098,19 @@ object({
5911
6098
  isDefault: boolean().optional(),
5912
6099
  value: credentialSecretValueSchema.optional()
5913
6100
  }).refine((input) => input.label !== void 0 || input.isDefault !== void 0 || input.value !== void 0, { message: "At least one field is required" });
5914
- const CredentialAssignmentTargetTypeSchema = _enum(["workflow", "agent"]);
6101
+ object({
6102
+ limit: number().int().min(1).max(200).optional(),
6103
+ cursor: string().min(1).optional()
6104
+ });
6105
+ object({
6106
+ items: array(AppCredentialSummarySchema),
6107
+ nextCursor: string().nullable()
6108
+ });
6109
+ const CredentialAssignmentTargetTypeSchema = _enum([
6110
+ "workflow",
6111
+ "agent",
6112
+ "poll"
6113
+ ]);
5915
6114
  object({ assignments: array(object({
5916
6115
  id: string(),
5917
6116
  targetType: CredentialAssignmentTargetTypeSchema,
@@ -6026,7 +6225,11 @@ const ValidationErrorDetailSchema = object({
6026
6225
  message: string()
6027
6226
  });
6028
6227
  /** Machine-readable codes returned in standard API error bodies. */
6029
- const ErrorResponseCodeSchema = OrganizationSlugErrorCodeSchema.or(_enum(["needs_org_selection", "org_unverified"]));
6228
+ const ErrorResponseCodeSchema = OrganizationSlugErrorCodeSchema.or(_enum([
6229
+ "needs_org_selection",
6230
+ "org_unverified",
6231
+ "connector_unavailable"
6232
+ ]));
6030
6233
  object({
6031
6234
  error: string(),
6032
6235
  code: ErrorResponseCodeSchema.optional(),
@@ -6137,6 +6340,17 @@ union([
6137
6340
  SkipResponseSchema,
6138
6341
  object({ runId: string() })
6139
6342
  ]);
6343
+ object({
6344
+ sql: string().min(1),
6345
+ params: array(unknown()).default([]),
6346
+ method: string().min(1).optional()
6347
+ });
6348
+ object({ migrations: array(object({
6349
+ sql: array(string().min(1)),
6350
+ hash: string().min(1),
6351
+ folderMillis: number$1()
6352
+ })) });
6353
+ object({ results: array(object({ rows: array(unknown()) })) });
6140
6354
  const RunSourceKindSchema = _enum([
6141
6355
  "api",
6142
6356
  "trigger",
@@ -6175,6 +6389,191 @@ object({
6175
6389
  attachmentId: string(),
6176
6390
  attachmentSlug: string()
6177
6391
  });
6392
+ const HistoryRunKindSchema = _enum(["workflow", "agent"]);
6393
+ const HistoryRunStatusSchema = _enum([
6394
+ "pending",
6395
+ "running",
6396
+ "sleeping",
6397
+ "waiting_hook",
6398
+ "completed",
6399
+ "failed",
6400
+ "canceled"
6401
+ ]);
6402
+ const HistoryRunActorSchema = object({
6403
+ userId: string(),
6404
+ name: string(),
6405
+ avatarUrl: string().nullable().optional()
6406
+ });
6407
+ const HistoryRunUsageLineItemSchema = object({
6408
+ id: string(),
6409
+ label: string(),
6410
+ /** Amount debited from the org's Keystroke balance for this line. */
6411
+ billedUsd: number$1(),
6412
+ /** Provider cost for LLM usage on the org's API key (informational; not billed by Keystroke). */
6413
+ providerCostUsd: number$1().nullable().optional(),
6414
+ keySource: _enum(["byok", "platform"]).nullable().optional()
6415
+ });
6416
+ const HistoryRunUsageSchema = object({
6417
+ runDurationMs: number$1().nullable(),
6418
+ lineItems: array(HistoryRunUsageLineItemSchema),
6419
+ /** Sum of `billedUsd` — what Keystroke charged for this run. */
6420
+ totalBilledUsd: number$1().nullable(),
6421
+ /** Sum of BYOK LLM provider costs (billed externally by the org's provider). */
6422
+ externalProviderCostUsd: number$1().nullable().optional()
6423
+ });
6424
+ const HistoryRunSchema = object({
6425
+ id: string(),
6426
+ kind: HistoryRunKindSchema,
6427
+ traceId: string().nullable(),
6428
+ projectId: string(),
6429
+ projectName: string(),
6430
+ resourceKey: string(),
6431
+ resourceId: string(),
6432
+ resourceName: string(),
6433
+ status: HistoryRunStatusSchema,
6434
+ triggeredAt: string(),
6435
+ timeInQueueMs: number$1().nullable(),
6436
+ startedAt: string(),
6437
+ finishedAt: string().nullable(),
6438
+ durationMs: number$1().nullable(),
6439
+ triggerLabel: string(),
6440
+ triggerRaw: string(),
6441
+ ranAs: HistoryRunActorSchema.nullable(),
6442
+ modelsUsed: array(string()),
6443
+ otherServicesUsed: array(string()),
6444
+ totalCostUsd: number$1().nullable(),
6445
+ messageCount: number$1().optional(),
6446
+ stepCount: number$1().optional()
6447
+ });
6448
+ const HistoryTraceSpanSchema = object({
6449
+ id: string(),
6450
+ traceId: string(),
6451
+ parentSpanId: string().nullable(),
6452
+ kind: string(),
6453
+ refId: string(),
6454
+ name: string(),
6455
+ status: string(),
6456
+ startedAt: string(),
6457
+ finishedAt: string().nullable(),
6458
+ metadata: unknown().nullable(),
6459
+ error: unknown().nullable()
6460
+ });
6461
+ const HistoryTraceLogSchema = object({
6462
+ id: string(),
6463
+ traceId: string(),
6464
+ spanId: string(),
6465
+ seq: number$1(),
6466
+ level: string(),
6467
+ message: string(),
6468
+ data: unknown().nullable(),
6469
+ source: string(),
6470
+ createdAt: string()
6471
+ });
6472
+ const HistoryTraceTriggerSchema = object({
6473
+ triggerType: string(),
6474
+ triggerRunId: string(),
6475
+ workflowKey: string().optional(),
6476
+ agentKey: string().optional(),
6477
+ attachmentId: string().nullable().optional(),
6478
+ attachmentSlug: string().nullable().optional(),
6479
+ route: string().optional(),
6480
+ sourcePath: string().nullable().optional()
6481
+ }).nullable();
6482
+ const HistoryTraceGatewaySchema = object({
6483
+ gatewayAttachmentId: string(),
6484
+ gatewayAttachmentKey: string(),
6485
+ threadId: string().optional(),
6486
+ channelId: string().optional(),
6487
+ mode: string().optional()
6488
+ }).nullable();
6489
+ const HistoryTraceSchema = object({
6490
+ traceId: string(),
6491
+ trigger: HistoryTraceTriggerSchema,
6492
+ gateway: HistoryTraceGatewaySchema,
6493
+ spans: array(HistoryTraceSpanSchema),
6494
+ logs: array(HistoryTraceLogSchema)
6495
+ });
6496
+ const HistoryWorkflowStepSchema = object({
6497
+ id: string(),
6498
+ actionKey: string(),
6499
+ output: unknown(),
6500
+ completedAt: string()
6501
+ });
6502
+ const HistoryWorkflowRunDetailSchema = object({
6503
+ kind: literal("workflow"),
6504
+ run: object({
6505
+ id: string(),
6506
+ workflowKey: string(),
6507
+ status: HistoryRunStatusSchema,
6508
+ trigger: string(),
6509
+ triggeredAt: string(),
6510
+ startedAt: string().nullable(),
6511
+ finishedAt: string().nullable(),
6512
+ input: unknown().nullable(),
6513
+ output: unknown().nullable(),
6514
+ error: unknown().nullable()
6515
+ }),
6516
+ trigger: object({
6517
+ id: string(),
6518
+ attachmentSlug: string().nullable(),
6519
+ triggerType: string(),
6520
+ sourcePath: string().nullable(),
6521
+ payload: unknown().nullable(),
6522
+ triggeredAt: string()
6523
+ }).nullable(),
6524
+ steps: array(HistoryWorkflowStepSchema),
6525
+ trace: HistoryTraceSchema.nullable(),
6526
+ ranAs: HistoryRunActorSchema.nullable().optional(),
6527
+ usage: HistoryRunUsageSchema.nullable().optional()
6528
+ });
6529
+ const HistoryAgentCompactionEventSchema = object({
6530
+ seq: number$1(),
6531
+ createdAt: string(),
6532
+ compactionModel: string(),
6533
+ sourceModel: string(),
6534
+ estimatedBeforeTokens: number$1().optional(),
6535
+ retainedTailEstimate: number$1().optional(),
6536
+ durable: boolean()
6537
+ });
6538
+ const HistoryRunDetailSchema = discriminatedUnion("kind", [HistoryWorkflowRunDetailSchema, object({
6539
+ kind: literal("agent"),
6540
+ runId: string(),
6541
+ session: object({
6542
+ id: string(),
6543
+ agentKey: string(),
6544
+ status: HistoryRunStatusSchema,
6545
+ source: _enum([
6546
+ "api",
6547
+ "gateway",
6548
+ "trigger",
6549
+ "workflow",
6550
+ "agent"
6551
+ ]),
6552
+ sourceId: string().nullable(),
6553
+ createdAt: string(),
6554
+ updatedAt: string(),
6555
+ messageCount: number$1(),
6556
+ error: unknown().nullable()
6557
+ }),
6558
+ gateway: object({
6559
+ threadId: string(),
6560
+ attachmentSlug: string().nullable()
6561
+ }).nullable(),
6562
+ messages: array(record(string(), unknown())),
6563
+ /** Sanitized context-compaction markers for the conversation timeline. */
6564
+ compactionEvents: array(HistoryAgentCompactionEventSchema).default([]),
6565
+ trace: HistoryTraceSchema.nullable(),
6566
+ ranAs: HistoryRunActorSchema.nullable().optional(),
6567
+ usage: HistoryRunUsageSchema.nullable().optional()
6568
+ })]);
6569
+ object({
6570
+ project: string().min(1).optional(),
6571
+ status: HistoryRunStatusSchema.optional(),
6572
+ kind: HistoryRunKindSchema.optional(),
6573
+ limit: number().int().min(1).max(200).optional()
6574
+ });
6575
+ HistoryRunDetailSchema.nullable();
6576
+ HistoryRunSchema.nullable();
6178
6577
  const WorkflowRunStatusSchema = _enum([
6179
6578
  "pending",
6180
6579
  "running",
@@ -6356,6 +6755,7 @@ const AgentSessionRecordSchema = object({
6356
6755
  status: AgentSessionStatusSchema,
6357
6756
  source: RunSourceKindSchema,
6358
6757
  sourceId: string().nullable(),
6758
+ title: string().nullable(),
6359
6759
  createdAt: string(),
6360
6760
  updatedAt: string(),
6361
6761
  parentSpanId: string().nullable(),
@@ -6394,17 +6794,18 @@ const AgentEventSchema = object({
6394
6794
  });
6395
6795
  object({
6396
6796
  session: AgentSessionRecordSchema,
6797
+ activeRunId: string().nullable().default(null),
6397
6798
  gateway: GatewaySessionDetailSchema.nullable(),
6398
6799
  messages: array(record(string(), unknown())),
6399
6800
  events: array(AgentEventSchema),
6801
+ /**
6802
+ * Sanitized context-compaction markers, populated alongside `messages`.
6803
+ * A cheap indexed lookup (session_id + event_type) — never the full event
6804
+ * log. Defaulted so older servers remain compatible.
6805
+ */
6806
+ compactionEvents: array(HistoryAgentCompactionEventSchema).default([]),
6400
6807
  trace: TraceResponseSchema.nullable()
6401
6808
  });
6402
- object({ sinceSeq: number().int().min(0).optional() });
6403
- object({
6404
- status: AgentSessionStatusSchema,
6405
- messages: array(record(string(), unknown())),
6406
- live: record(string(), unknown()).nullable()
6407
- });
6408
6809
  const SlackGatewayModeSchema = _enum([
6409
6810
  "mention",
6410
6811
  "channel",
@@ -6439,171 +6840,6 @@ object({ agents: array(object({
6439
6840
  name: string().optional(),
6440
6841
  route: string()
6441
6842
  })) });
6442
- const HistoryRunKindSchema = _enum(["workflow", "agent"]);
6443
- const HistoryRunStatusSchema = _enum([
6444
- "pending",
6445
- "running",
6446
- "sleeping",
6447
- "waiting_hook",
6448
- "completed",
6449
- "failed",
6450
- "canceled"
6451
- ]);
6452
- const HistoryRunActorSchema = object({
6453
- userId: string(),
6454
- name: string(),
6455
- avatarUrl: string().nullable().optional()
6456
- });
6457
- const HistoryRunUsageLineItemSchema = object({
6458
- id: string(),
6459
- label: string(),
6460
- amountUsd: number$1()
6461
- });
6462
- const HistoryRunUsageSchema = object({
6463
- runDurationMs: number$1().nullable(),
6464
- lineItems: array(HistoryRunUsageLineItemSchema),
6465
- totalExcludingDurationUsd: number$1().nullable()
6466
- });
6467
- const HistoryRunSchema = object({
6468
- id: string(),
6469
- kind: HistoryRunKindSchema,
6470
- traceId: string().nullable(),
6471
- projectId: string(),
6472
- projectName: string(),
6473
- resourceKey: string(),
6474
- resourceId: string(),
6475
- resourceName: string(),
6476
- status: HistoryRunStatusSchema,
6477
- triggeredAt: string(),
6478
- timeInQueueMs: number$1().nullable(),
6479
- startedAt: string(),
6480
- finishedAt: string().nullable(),
6481
- durationMs: number$1().nullable(),
6482
- triggerLabel: string(),
6483
- triggerRaw: string(),
6484
- ranAs: HistoryRunActorSchema.nullable(),
6485
- modelsUsed: array(string()),
6486
- otherServicesUsed: array(string()),
6487
- totalCostUsd: number$1().nullable(),
6488
- messageCount: number$1().optional(),
6489
- stepCount: number$1().optional()
6490
- });
6491
- const HistoryTraceSpanSchema = object({
6492
- id: string(),
6493
- traceId: string(),
6494
- parentSpanId: string().nullable(),
6495
- kind: string(),
6496
- refId: string(),
6497
- name: string(),
6498
- status: string(),
6499
- startedAt: string(),
6500
- finishedAt: string().nullable(),
6501
- metadata: unknown().nullable(),
6502
- error: unknown().nullable()
6503
- });
6504
- const HistoryTraceLogSchema = object({
6505
- id: string(),
6506
- traceId: string(),
6507
- spanId: string(),
6508
- seq: number$1(),
6509
- level: string(),
6510
- message: string(),
6511
- data: unknown().nullable(),
6512
- source: string(),
6513
- createdAt: string()
6514
- });
6515
- const HistoryTraceTriggerSchema = object({
6516
- triggerType: string(),
6517
- triggerRunId: string(),
6518
- workflowKey: string().optional(),
6519
- agentKey: string().optional(),
6520
- attachmentId: string().nullable().optional(),
6521
- attachmentSlug: string().nullable().optional(),
6522
- route: string().optional(),
6523
- sourcePath: string().nullable().optional()
6524
- }).nullable();
6525
- const HistoryTraceGatewaySchema = object({
6526
- gatewayAttachmentId: string(),
6527
- gatewayAttachmentKey: string(),
6528
- threadId: string().optional(),
6529
- channelId: string().optional(),
6530
- mode: string().optional()
6531
- }).nullable();
6532
- const HistoryTraceSchema = object({
6533
- traceId: string(),
6534
- trigger: HistoryTraceTriggerSchema,
6535
- gateway: HistoryTraceGatewaySchema,
6536
- spans: array(HistoryTraceSpanSchema),
6537
- logs: array(HistoryTraceLogSchema)
6538
- });
6539
- const HistoryWorkflowStepSchema = object({
6540
- id: string(),
6541
- actionKey: string(),
6542
- output: unknown(),
6543
- completedAt: string()
6544
- });
6545
- const HistoryRunDetailSchema = discriminatedUnion("kind", [object({
6546
- kind: literal("workflow"),
6547
- run: object({
6548
- id: string(),
6549
- workflowKey: string(),
6550
- status: HistoryRunStatusSchema,
6551
- trigger: string(),
6552
- triggeredAt: string(),
6553
- startedAt: string().nullable(),
6554
- finishedAt: string().nullable(),
6555
- input: unknown().nullable(),
6556
- output: unknown().nullable(),
6557
- error: unknown().nullable()
6558
- }),
6559
- trigger: object({
6560
- id: string(),
6561
- attachmentSlug: string().nullable(),
6562
- triggerType: string(),
6563
- sourcePath: string().nullable(),
6564
- payload: unknown().nullable(),
6565
- triggeredAt: string()
6566
- }).nullable(),
6567
- steps: array(HistoryWorkflowStepSchema),
6568
- trace: HistoryTraceSchema.nullable(),
6569
- ranAs: HistoryRunActorSchema.nullable().optional(),
6570
- usage: HistoryRunUsageSchema.nullable().optional()
6571
- }), object({
6572
- kind: literal("agent"),
6573
- runId: string(),
6574
- session: object({
6575
- id: string(),
6576
- agentKey: string(),
6577
- status: HistoryRunStatusSchema,
6578
- source: _enum([
6579
- "api",
6580
- "gateway",
6581
- "trigger",
6582
- "workflow",
6583
- "agent"
6584
- ]),
6585
- sourceId: string().nullable(),
6586
- createdAt: string(),
6587
- updatedAt: string(),
6588
- messageCount: number$1(),
6589
- error: unknown().nullable()
6590
- }),
6591
- gateway: object({
6592
- threadId: string(),
6593
- attachmentSlug: string().nullable()
6594
- }).nullable(),
6595
- messages: array(record(string(), unknown())),
6596
- trace: HistoryTraceSchema.nullable(),
6597
- ranAs: HistoryRunActorSchema.nullable().optional(),
6598
- usage: HistoryRunUsageSchema.nullable().optional()
6599
- })]);
6600
- object({
6601
- project: string().min(1).optional(),
6602
- status: HistoryRunStatusSchema.optional(),
6603
- kind: HistoryRunKindSchema.optional()
6604
- });
6605
- HistoryRunDetailSchema.nullable();
6606
- HistoryRunSchema.nullable();
6607
6843
  object({ subscriptions: array(object({
6608
6844
  id: string(),
6609
6845
  workflowKey: string(),
@@ -6698,7 +6934,8 @@ const TriggerRunRecordSchema = object({
6698
6934
  object({
6699
6935
  limit: number().int().min(1).max(100).optional().default(20),
6700
6936
  cursor: string().min(1).optional(),
6701
- triggerType: TriggerRunTypeSchema.optional()
6937
+ triggerType: TriggerRunTypeSchema.optional(),
6938
+ outcome: TriggerRunOutcomeSchema.optional()
6702
6939
  });
6703
6940
  object({
6704
6941
  items: array(TriggerRunSummarySchema),
@@ -6766,7 +7003,8 @@ const WorkspaceTriggerRunStatusSchema = _enum([
6766
7003
  const WorkspaceTriggerSkipReasonSchema = _enum([
6767
7004
  "filtered",
6768
7005
  "no_new_data",
6769
- "transform_undefined"
7006
+ "transform_undefined",
7007
+ "payload_mismatch"
6770
7008
  ]);
6771
7009
  /**
6772
7010
  * A single downstream run/session a dispatched fire produced. A fan-out fire can
@@ -6797,7 +7035,9 @@ const WorkspaceTriggerRunOutcomeSchema = discriminatedUnion("kind", [
6797
7035
  }),
6798
7036
  object({
6799
7037
  kind: literal("skipped"),
6800
- reason: WorkspaceTriggerSkipReasonSchema
7038
+ reason: WorkspaceTriggerSkipReasonSchema,
7039
+ /** One-line Zod issue summary when reason is payload_mismatch. */
7040
+ detail: string().nullable().optional()
6801
7041
  }),
6802
7042
  object({
6803
7043
  kind: literal("failed"),
@@ -6870,6 +7110,30 @@ object({
6870
7110
  input: TriggerOverviewInputSchema
6871
7111
  });
6872
7112
  object({ enabled: boolean() });
7113
+ object({
7114
+ input: unknown().optional(),
7115
+ workflow: string().min(1).optional(),
7116
+ agent: string().min(1).optional()
7117
+ });
7118
+ object({ runId: string().min(1) });
7119
+ object({
7120
+ type: TriggerTypeSchema,
7121
+ attachments: array(object({
7122
+ attachmentSlug: string().min(1),
7123
+ kind: TriggerTargetKindSchema,
7124
+ targetSlug: string().min(1),
7125
+ targetName: string().min(1),
7126
+ enabled: boolean(),
7127
+ /** Webhook attachment JSON Schema used to drive the invoke form. */
7128
+ requestSchema: record(string(), unknown()).optional()
7129
+ })),
7130
+ /** Cron source static payload — display only; never overridden on invoke. */
7131
+ staticPayload: unknown().optional()
7132
+ });
7133
+ object({
7134
+ manual: literal(true),
7135
+ attachments: array(string().min(1)).optional()
7136
+ });
6873
7137
  const OrganizationMemberRoleSchema = _enum([
6874
7138
  "owner",
6875
7139
  "admin",
@@ -6882,16 +7146,24 @@ const OrganizationMemberStatusSchema = _enum([
6882
7146
  "suspended"
6883
7147
  ]);
6884
7148
  const InvitableOrganizationMemberRoleSchema = _enum(["admin", "builder"]);
6885
- const isoDateTime$4 = string().datetime();
6886
- object({
7149
+ const isoDateTime$5 = string().datetime();
7150
+ const OrganizationMemberSchema = object({
6887
7151
  id: string(),
6888
7152
  name: string(),
6889
7153
  email: string().email(),
6890
7154
  role: OrganizationMemberRoleSchema,
6891
7155
  status: OrganizationMemberStatusSchema,
6892
7156
  avatarUrl: string().optional(),
6893
- joinedAt: isoDateTime$4.optional(),
6894
- lastActiveAt: isoDateTime$4.nullable().optional()
7157
+ joinedAt: isoDateTime$5.optional(),
7158
+ lastActiveAt: isoDateTime$5.nullable().optional()
7159
+ });
7160
+ object({
7161
+ limit: number().int().min(1).max(200).optional(),
7162
+ cursor: string().min(1).optional()
7163
+ });
7164
+ object({
7165
+ items: array(OrganizationMemberSchema),
7166
+ nextCursor: string().nullable()
6895
7167
  });
6896
7168
  object({
6897
7169
  emails: array(string().trim().email()).min(1),
@@ -6918,7 +7190,7 @@ object({
6918
7190
  role: OrganizationMemberRoleSchema
6919
7191
  });
6920
7192
  object({ success: literal(true) });
6921
- const isoDateTime$3 = string().datetime();
7193
+ const isoDateTime$4 = string().datetime();
6922
7194
  const ApiKeyCreatorSchema = object({
6923
7195
  id: string(),
6924
7196
  name: string(),
@@ -6931,12 +7203,37 @@ const ApiKeySummarySchema = object({
6931
7203
  id: string(),
6932
7204
  name: string(),
6933
7205
  keyPreview: string(),
6934
- createdAt: isoDateTime$3,
7206
+ createdAt: isoDateTime$4,
6935
7207
  createdBy: ApiKeyCreatorSchema,
6936
7208
  isCreatedByCurrentUser: boolean()
6937
7209
  });
6938
7210
  object({ name: string().trim().min(1).max(128) });
6939
7211
  ApiKeySummarySchema.extend({ secret: string() });
7212
+ const isoDateTime$3 = string().datetime();
7213
+ const ManagedServiceKindSchema = _enum(["llm"]);
7214
+ _enum([
7215
+ "openai",
7216
+ "anthropic",
7217
+ "google",
7218
+ "groq",
7219
+ "xai"
7220
+ ]);
7221
+ object({
7222
+ id: string(),
7223
+ kind: ManagedServiceKindSchema,
7224
+ provider: string(),
7225
+ keyPreview: string(),
7226
+ createdAt: isoDateTime$3,
7227
+ updatedAt: isoDateTime$3,
7228
+ createdBy: ApiKeyCreatorSchema,
7229
+ isCreatedByCurrentUser: boolean()
7230
+ });
7231
+ object({
7232
+ kind: ManagedServiceKindSchema.default("llm"),
7233
+ provider: string().trim().min(1),
7234
+ apiKey: string().trim().min(1)
7235
+ });
7236
+ object({ apiKey: string().trim().min(1) });
6940
7237
  const ProjectUserRoleSchema = _enum(["admin", "builder"]);
6941
7238
  const ProjectInvitePermissionSchema = _enum(["admin", "all"]);
6942
7239
  const ProjectMemberStatusSchema = _enum(["active", "invited"]);
@@ -6986,14 +7283,6 @@ object({
6986
7283
  uploadUrl: url(),
6987
7284
  storageKey: string().min(1)
6988
7285
  });
6989
- function isValidIanaTimezone(value) {
6990
- try {
6991
- Intl.DateTimeFormat(void 0, { timeZone: value });
6992
- return true;
6993
- } catch {
6994
- return false;
6995
- }
6996
- }
6997
7286
  const UserInterfaceThemeSchema = _enum([
6998
7287
  "system",
6999
7288
  "light",
@@ -7514,17 +7803,48 @@ function parseOrgArtifactsFromEnv(env = process.env) {
7514
7803
  });
7515
7804
  }
7516
7805
  //#endregion
7806
+ //#region src/org-worker-token.ts
7807
+ function sign(secret, organizationId) {
7808
+ return (0, node_crypto.createHmac)("sha256", secret).update(`org-worker:${organizationId}`).digest("base64url");
7809
+ }
7810
+ /**
7811
+ * Per-org worker token: `{organizationId}.{hmac}`. Self-describing so the
7812
+ * platform can tell which org a machine is calling as, and stateless — verified
7813
+ * by re-signing with the shared `PLATFORM_WORKER_TOKEN` secret.
7814
+ */
7815
+ function mintOrgWorkerToken(secret, organizationId) {
7816
+ return `${organizationId}.${sign(secret, organizationId)}`;
7817
+ }
7818
+ function verifyOrgWorkerToken(secret, token) {
7819
+ if (!secret || !token) return;
7820
+ const separator = token.lastIndexOf(".");
7821
+ if (separator <= 0) return;
7822
+ const organizationId = token.slice(0, separator);
7823
+ const signature = Buffer.from(token.slice(separator + 1));
7824
+ const expected = Buffer.from(sign(secret, organizationId));
7825
+ if (signature.length !== expected.length || !(0, node_crypto.timingSafeEqual)(signature, expected)) return;
7826
+ return { organizationId };
7827
+ }
7828
+ //#endregion
7517
7829
  //#region src/runtime-env.ts
7830
+ /** Non-secret runtime config forwarded into org workers. Never include platform secrets. */
7518
7831
  const RUNTIME_ENV_KEYS = [
7519
- "BETTER_AUTH_SECRET",
7520
7832
  "PUBLIC_PLATFORM_URL",
7521
7833
  "PUBLIC_PLATFORM_PROXY_URL",
7522
7834
  "PUBLIC_WEB_URL",
7523
- "POSTGRES_SSL",
7524
7835
  "UPSTASH_REDIS_URL",
7525
7836
  "REDIS_URL",
7526
7837
  "KEYSTROKE_QUEUE_PREFIX"
7527
7838
  ];
7839
+ /** Env keys that must never be forwarded into untrusted org workers. */
7840
+ const FORBIDDEN_WORKER_ENV_KEYS = [
7841
+ "BETTER_AUTH_SECRET",
7842
+ "DATABASE_URL",
7843
+ "POSTGRES_PASSWORD",
7844
+ "PLATFORM_WORKER_TOKEN",
7845
+ "STRIPE_SECRET_KEY",
7846
+ "CREDENTIAL_ENCRYPTION_KEY"
7847
+ ];
7528
7848
  /** Provider and gateway env forwarded from the platform into project servers. */
7529
7849
  const PROVIDER_ENV_KEYS = [
7530
7850
  "ANTHROPIC_API_KEY",
@@ -7534,25 +7854,6 @@ const PROVIDER_ENV_KEYS = [
7534
7854
  ];
7535
7855
  /** Shared dev token when `PLATFORM_WORKER_TOKEN` is unset (non-production only). */
7536
7856
  const DEV_PLATFORM_WORKER_TOKEN = "dev-platform-worker-token";
7537
- const PROJECT_DATABASE_ENV_KEYS = [
7538
- "POSTGRES_HOST",
7539
- "POSTGRES_PORT",
7540
- "POSTGRES_DB",
7541
- "POSTGRES_USER",
7542
- "POSTGRES_PASSWORD",
7543
- "DATABASE_SEARCH_PATH"
7544
- ];
7545
- /** Per-project postgres env injected into every project server container/machine. */
7546
- function projectDatabaseRuntimeEnv(database) {
7547
- return {
7548
- POSTGRES_HOST: rewriteLoopbackHost(database.host),
7549
- POSTGRES_PORT: String(database.port),
7550
- POSTGRES_DB: database.database,
7551
- POSTGRES_USER: database.user,
7552
- POSTGRES_PASSWORD: database.password,
7553
- DATABASE_SEARCH_PATH: database.searchPath
7554
- };
7555
- }
7556
7857
  /**
7557
7858
  * Builds the launch spec for an org worker. Each deploy artifact is encoded in
7558
7859
  * `KEYSTROKE_ORG_ARTIFACTS` — there is no base image, so at least one artifact is required.
@@ -7579,10 +7880,7 @@ function buildRuntimeEnv(source, artifacts, database, extraEnv) {
7579
7880
  ]);
7580
7881
  for (const key of RUNTIME_ENV_KEYS) {
7581
7882
  const value = source[key]?.trim();
7582
- if (!value) {
7583
- if (key === "POSTGRES_SSL") throw new Error("POSTGRES_SSL is required");
7584
- continue;
7585
- }
7883
+ if (!value) continue;
7586
7884
  entries.set(key, value);
7587
7885
  }
7588
7886
  if (!extraEnv) for (const key of PROVIDER_ENV_KEYS) {
@@ -7591,9 +7889,9 @@ function buildRuntimeEnv(source, artifacts, database, extraEnv) {
7591
7889
  }
7592
7890
  const worker = resolveWorkerRuntimeConfig(source);
7593
7891
  entries.set("PLATFORM_URL", worker.platformUrl);
7594
- entries.set("WORKER_INTERNAL_TOKEN", worker.workerToken);
7595
- for (const [key, value] of Object.entries(projectDatabaseRuntimeEnv(database))) entries.set(key, value);
7892
+ entries.set("WORKER_INTERNAL_TOKEN", mintOrgWorkerToken(worker.workerToken, database.organizationId));
7596
7893
  if (extraEnv) for (const [key, value] of Object.entries(extraEnv)) entries.set(key, value);
7894
+ for (const key of FORBIDDEN_WORKER_ENV_KEYS) entries.delete(key);
7597
7895
  return Object.fromEntries(entries);
7598
7896
  }
7599
7897
  function resolvePlatformWorkerToken(source = process.env) {
@@ -7845,7 +8143,7 @@ async function fetchDeployStatus(baseUrl, options = {}) {
7845
8143
  }
7846
8144
  //#endregion
7847
8145
  exports.DEV_PLATFORM_WORKER_TOKEN = DEV_PLATFORM_WORKER_TOKEN;
7848
- exports.PROJECT_DATABASE_ENV_KEYS = PROJECT_DATABASE_ENV_KEYS;
8146
+ exports.FORBIDDEN_WORKER_ENV_KEYS = FORBIDDEN_WORKER_ENV_KEYS;
7849
8147
  exports.PROJECT_SERVER_DEPLOY_STATUS = PROJECT_SERVER_DEPLOY_STATUS;
7850
8148
  exports.PROJECT_SERVER_FRAMEWORK_NODE_MODULES = PROJECT_SERVER_FRAMEWORK_NODE_MODULES;
7851
8149
  exports.PROJECT_SERVER_FRAMEWORK_ROOT = PROJECT_SERVER_FRAMEWORK_ROOT;
@@ -7862,10 +8160,10 @@ exports.dockerPlugin = dockerPlugin;
7862
8160
  exports.encodeOrgArtifacts = encodeOrgArtifacts;
7863
8161
  exports.fetchDeployStatus = fetchDeployStatus;
7864
8162
  exports.formatDockerEnv = formatDockerEnv;
8163
+ exports.mintOrgWorkerToken = mintOrgWorkerToken;
7865
8164
  exports.parseOrgArtifactsFromEnv = parseOrgArtifactsFromEnv;
7866
8165
  exports.pingProject = pingProject;
7867
8166
  exports.pingProjectTarget = pingProjectTarget;
7868
- exports.projectDatabaseRuntimeEnv = projectDatabaseRuntimeEnv;
7869
8167
  exports.resolvePlatformWorkerToken = resolvePlatformWorkerToken;
7870
8168
  exports.resolveProjectServerImage = resolveProjectServerImage;
7871
8169
  exports.resolveRuntimeLaunch = resolveRuntimeLaunch;
@@ -7873,6 +8171,7 @@ exports.resolveWorkerPlatformUrl = resolveWorkerPlatformUrl;
7873
8171
  exports.resolveWorkerRuntimeConfig = resolveWorkerRuntimeConfig;
7874
8172
  exports.rewriteLoopbackHost = rewriteLoopbackHost;
7875
8173
  exports.rewriteLoopbackUrl = rewriteLoopbackUrl;
8174
+ exports.verifyOrgWorkerToken = verifyOrgWorkerToken;
7876
8175
  exports.waitForHealth = waitForHealth;
7877
8176
 
7878
8177
  //# sourceMappingURL=index.cjs.map