@badger_badger/badger_hq 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -193,6 +193,50 @@ var COLLECTIONS = {
193
193
  captures: "captures",
194
194
  llmCalls: "llmCalls"
195
195
  };
196
+ var HOUR_MS = 36e5;
197
+ var VISIT_INTERVAL_MIN_MS = 1 * HOUR_MS;
198
+ var VISIT_INTERVAL_MAX_MS = 72 * HOUR_MS;
199
+ var URGENCY_FACTOR = {
200
+ emergency: 0.5,
201
+ missionPriority: { critical: 0.5, high: 0.75, medium: 1, low: 1.5 }
202
+ };
203
+ var OverdueLevelSchema = z.enum(["none", "late", "missed"]);
204
+ function knownInterval(source) {
205
+ if (source.visitIntervalMs) return { ms: source.visitIntervalMs, urgencyApplied: false };
206
+ if (source.lastCollectedAt && source.nextVisitAt) {
207
+ const derived = source.nextVisitAt.getTime() - source.lastCollectedAt.getTime();
208
+ if (derived > 0) return { ms: derived, urgencyApplied: true };
209
+ }
210
+ return void 0;
211
+ }
212
+ function baseVisitInterval(source) {
213
+ return knownInterval(source)?.ms;
214
+ }
215
+ function urgencyFactor(urgency) {
216
+ const priority = urgency.missionPriority ? URGENCY_FACTOR.missionPriority[urgency.missionPriority] : 1;
217
+ return (urgency.emergency ? URGENCY_FACTOR.emergency : 1) * priority;
218
+ }
219
+ function clampInterval(ms) {
220
+ return Math.min(Math.max(ms, VISIT_INTERVAL_MIN_MS), VISIT_INTERVAL_MAX_MS);
221
+ }
222
+ function effectiveInterval(source, urgency) {
223
+ const known = knownInterval(source);
224
+ if (!known) return void 0;
225
+ return clampInterval(known.urgencyApplied ? known.ms : known.ms * urgencyFactor(urgency));
226
+ }
227
+ function effectiveDueAt(source, urgency, now = /* @__PURE__ */ new Date()) {
228
+ if (source.status === "access_problem") return void 0;
229
+ if (!source.lastCollectedAt) return now;
230
+ const interval = effectiveInterval(source, urgency);
231
+ if (interval === void 0) return source.nextVisitAt ?? now;
232
+ return new Date(source.lastCollectedAt.getTime() + interval);
233
+ }
234
+ function overdueLevel(dueAt, intervalMs, now = /* @__PURE__ */ new Date()) {
235
+ if (!dueAt) return "none";
236
+ const lateMs = now.getTime() - dueAt.getTime();
237
+ if (lateMs <= 0) return "none";
238
+ return intervalMs !== void 0 && lateMs > intervalMs ? "missed" : "late";
239
+ }
196
240
  var DatabaseName = z.string().min(1).max(63).regex(/^[^/\\. "$*<>:|?]+$/, "Invalid MongoDB database name");
197
241
  var ConnectionString = z.string().min(1).regex(/^mongodb(\+srv)?:\/\/\S+$/, "Expected a mongodb:// or mongodb+srv:// URI");
198
242
  var DatabaseSchema = z.object({
@@ -232,6 +276,7 @@ var TaskCriteriaSchema = z.object({
232
276
  emergency: z.boolean().default(false)
233
277
  });
234
278
  var MAX_CAPTURE_WINDOW_DAYS = 90;
279
+ var MONITOR_TASK_MAX_SOURCES = 20;
235
280
  var DAY_MS = 24 * 60 * 60 * 1e3;
236
281
  function isHttpUrl(value) {
237
282
  try {
@@ -536,6 +581,21 @@ var DiscoveredBySchema = z.object({
536
581
  userId: ClerkUserId.optional(),
537
582
  importId: ObjectIdString.optional()
538
583
  });
584
+ var SourceDiscoverySchema = z.object({
585
+ /** The Discovery task whose capture found it. */
586
+ taskId: ObjectIdString,
587
+ /** agent-service capture id, when the source came from a task-tagged capture. */
588
+ captureId: ObjectIdString.optional(),
589
+ /** The page the person captured (e.g. a search or hashtag page), not the source itself. */
590
+ capturedUrl: z.string().url().refine(isHttpUrl, "Expected an http(s) URL").optional(),
591
+ name: z.string().min(1).max(200),
592
+ description: z.string().max(1e3).optional(),
593
+ /** The judge's reason for keeping it. */
594
+ reason: z.string().max(300),
595
+ /** 0..1 relevance from the `judge` capability. */
596
+ relevanceScore: z.number().min(0).max(1),
597
+ discoveredAt: z.coerce.date()
598
+ });
539
599
  var SourceSchema = z.object({
540
600
  _id: ObjectIdString,
541
601
  orgId: ClerkOrgId,
@@ -553,8 +613,11 @@ var SourceSchema = z.object({
553
613
  tags: z.array(z.string().min(1)).default([]),
554
614
  status: SourceStatus.default("active"),
555
615
  discoveredBy: DiscoveredBySchema,
616
+ discovery: SourceDiscoverySchema.optional(),
556
617
  lastCollectedAt: z.coerce.date().optional(),
557
- nextVisitAt: z.coerce.date().optional()
618
+ nextVisitAt: z.coerce.date().optional(),
619
+ /** Activity-based wait set by the last visit, before current urgency (see `effectiveDueAt`). */
620
+ visitIntervalMs: z.number().int().positive().optional()
558
621
  }).merge(TimestampsSchema).merge(SoftDeleteSchema);
559
622
  var SourceCreateSchema = SourceSchema.omit({
560
623
  _id: true,
@@ -564,7 +627,9 @@ var SourceCreateSchema = SourceSchema.omit({
564
627
  updatedAt: true,
565
628
  deletedAt: true,
566
629
  discoveredBy: true,
567
- lastCollectedAt: true
630
+ discovery: true,
631
+ lastCollectedAt: true,
632
+ visitIntervalMs: true
568
633
  });
569
634
  var SourceUpdateSchema = SourceCreateSchema.partial();
570
635
  var MAX_SOURCE_IMPORT_ROW_ERRORS = 500;
@@ -996,6 +1061,16 @@ var AgentTaskCriteriaSchema = z.object({
996
1061
  emergency: z.boolean()
997
1062
  });
998
1063
  var AgentTaskTargetSchema = TaskTargetSchema.omit({ sourceId: true });
1064
+ var AgentTaskSourceSchema = z.object({
1065
+ platform: Platform,
1066
+ url: z.string().url().refine(isHttpUrl, "Expected an http(s) URL"),
1067
+ label: z.string().min(1).optional(),
1068
+ lastCapturedAt: z.coerce.date().optional(),
1069
+ /** When to capture it again, under current urgency (absent: parked on an access problem). */
1070
+ dueAt: z.coerce.date().optional(),
1071
+ /** Parked: a person couldn't get in; an analyst reviews it. */
1072
+ accessProblem: z.boolean().optional()
1073
+ });
999
1074
  var AgentTaskSchema = z.object({
1000
1075
  id: ObjectIdString,
1001
1076
  title: z.string(),
@@ -1005,6 +1080,8 @@ var AgentTaskSchema = z.object({
1005
1080
  searchQueries: z.array(z.string()),
1006
1081
  criteria: AgentTaskCriteriaSchema,
1007
1082
  target: AgentTaskTargetSchema.optional(),
1083
+ /** Monitor: the attached sources other than `target`, sorted by platform then URL. */
1084
+ sources: z.array(AgentTaskSourceSchema).default([]),
1008
1085
  captureWindow: CaptureWindowSchema.optional(),
1009
1086
  status: TaskStatus,
1010
1087
  version: z.number().int().min(1),
@@ -1026,7 +1103,9 @@ var AgentAssignmentsResponseSchema = z.object({
1026
1103
  });
1027
1104
  var AgentAssignmentVersionSchema = z.object({
1028
1105
  assignmentId: ObjectIdString,
1029
- taskVersion: z.number().int().min(1)
1106
+ taskVersion: z.number().int().min(1),
1107
+ /** Monitor: the latest change to any attached source (a visit moves it; the task version doesn't). */
1108
+ sourcesUpdatedAt: z.coerce.date().optional()
1030
1109
  });
1031
1110
  var AgentAssignmentVersionsResponseSchema = z.object({
1032
1111
  items: z.array(AgentAssignmentVersionSchema)
@@ -1143,6 +1222,10 @@ var SourceIntakeBodySchema = z.object({
1143
1222
  /** The discovery task the session works; its mission's monitor task receives gated sources. */
1144
1223
  taskId: ObjectIdString,
1145
1224
  discoveredByUserId: ClerkUserId,
1225
+ /** agent-service capture the candidates came from (task-tagged captures). */
1226
+ captureId: ObjectIdString.optional(),
1227
+ /** The page that capture was taken on. */
1228
+ capturedUrl: z.string().url().refine(isHttpUrl, "Expected an http(s) URL").optional(),
1146
1229
  candidates: z.array(SourceIntakeCandidateSchema).min(1).max(MAX_SOURCE_INTAKE_CANDIDATES)
1147
1230
  });
1148
1231
  var SourceIntakeResultSchema = z.object({
@@ -1187,6 +1270,6 @@ var PriorityAlertResponseSchema = z.object({
1187
1270
  var INTERNAL_ERROR_CODE_VALUES = ["UNAUTHENTICATED", "NOT_FOUND", "VALIDATION_ERROR", "INTERNAL"];
1188
1271
  var InternalErrorCode = z.enum(INTERNAL_ERROR_CODE_VALUES);
1189
1272
 
1190
- export { ACCESS_ISSUE_VALUES, AGENT_CARD_KIND_VALUES, AGENT_ERROR_CODE_VALUES, AGENT_MESSAGE_KIND_VALUES, AGENT_MESSAGE_ROLE_VALUES, AGENT_ROLE_VALUES, AGENT_SESSION_MODE_VALUES, AGENT_SESSION_STATUS_VALUES, AGENT_SOURCE_OUTCOME_VALUES, ASSIGNEE_TYPE_VALUES, ASSIGNMENT_SOURCE_VALUES, ASSIGNMENT_STATUS_VALUES, AccessIssue, AgentActiveSessionResponseSchema, AgentAssignmentItemSchema, AgentAssignmentVersionSchema, AgentAssignmentVersionsResponseSchema, AgentAssignmentsResponseSchema, AgentCaptureFieldsSchema, AgentCaptureResponseSchema, AgentCardKind, AgentCardSchema, AgentErrorCode, AgentErrorSchema, AgentMeSchema, AgentMessageCreateSchema, AgentMessageKind, AgentMessageRole, AgentMessageSchema, AgentMessageViewSchema, AgentMessagesQuerySchema, AgentMessagesResponseSchema, AgentOrgRefSchema, AgentReplyBodySchema, AgentRole, AgentSessionBudgetSchema, AgentSessionCreateSchema, AgentSessionMode, AgentSessionResponseSchema, AgentSessionSchema, AgentSessionStartBodySchema, AgentSessionStartResponseSchema, AgentSessionStatsSchema, AgentSessionStatus, AgentSessionUpdateSchema, AgentSessionViewSchema, AgentSourceOutcome, AgentStreamEventSchema, AgentTaskCriteriaSchema, AgentTaskSchema, AgentTaskTargetSchema, AnalystProfileSchema, AnalystProfileUpdateSchema, ApiErrorSchema, AssigneeLoadSchema, AssigneeType, AssignmentCreateSchema, AssignmentSchema, AssignmentSource, AssignmentStatus, AssignmentUpdateSchema, AuditLogCreateSchema, AuditLogSchema, AuditLogUpdateSchema, AuditTargetSchema, AvailabilityWindowSchema, BlobRefSchema, CAPTURE_DOM_STATUS_VALUES, CAPTURE_STATUS_VALUES, CAPTURE_WINDOW_MODE_VALUES, COLLECTIONS, COLLECTOR_TYPE_VALUES, CaptureCreateSchema, CaptureDomSnapshotSchema, CaptureDomStatus, CaptureDomSummarySchema, CapturePromptCardSchema, CaptureRegionSchema, CaptureSchema, CaptureStatus, CaptureThumbCardSchema, CaptureWindowMode, CaptureWindowSchema, ClerkOrgId, ClerkUserId, CollectorSchema, CollectorType, ConnectionString, CoverageWindowSchema, DATABASE_COLLECTION_VALUES, DATABASE_STATUS_VALUES, DEFAULT_ANALYST_TASK_LIMIT, DEFAULT_SCOUT_TASK_LIMIT, DEPLOYMENT_KIND_VALUES, DEPLOYMENT_STATUS_VALUES, DISCOVERED_BY_TYPE_VALUES, DataItemContentSchema, DataItemCreateSchema, DataItemEntitySchema, DataItemSchema, DataItemUpdateSchema, DatabaseCollection, DatabaseCreateSchema, DatabaseId, DatabaseName, DatabaseSchema, DatabaseStatus, DatabaseUpdateSchema, DeploymentCreateSchema, DeploymentKind, DeploymentSchema, DeploymentStatus, DeploymentStepSchema, DeploymentUpdateSchema, DiscoveredBySchema, DiscoveredByType, DomBlockSchema, DomLinkSchema, DomRectSchema, Email, GLOBAL_LOAD_SCOPE, GeoSchema, HHmm, HOURS_LOG_SOURCE_VALUES, HoursLogCreateSchema, HoursLogSchema, HoursLogSource, HoursLogUpdateSchema, HoursProposalCardSchema, INTERNAL_ERROR_CODE_VALUES, InternalErrorCode, ItemResultCardSchema, LLM_CAPABILITY_VALUES, LLM_OUTCOME_VALUES, LLM_PROVIDER_VALUES, LanguageCode, LlmCallCreateSchema, LlmCallSchema, LlmCapability, LlmOutcome, LlmProvider, LlmUsageSchema, LoadScope, MAX_AGENT_MESSAGE_TEXT_LENGTH, MAX_CAPTURE_WINDOW_DAYS, MAX_RATING_COMMENT_LENGTH, MAX_SOURCE_IMPORT_ROW_ERRORS, MAX_SOURCE_INTAKE_CANDIDATES, MISSION_PRIORITY_VALUES, MISSION_STATUS_VALUES, MatchingFieldsSchema, MissionCreateSchema, MissionPriority, MissionSchema, MissionStatus, MissionUpdateSchema, ObjectIdString, OpenLinkCardSchema, OrgSettingsSchema, OrgSettingsUpdateSchema, PLATFORM_VALUES, PaginatedSchema, PaginationQuerySchema, Platform, PlatformAccessSchema, PriorityAlertBodySchema, PriorityAlertResponseSchema, QuickRepliesCardSchema, QuickReplyOptionSchema, RATER_TYPE_VALUES, REGION_MODE_VALUES, RaterType, RatingScore, RatingSummarySchema, RegionMode, SCOUT_STATUS_VALUES, SCRAPER_STATUS_VALUES, SERVER_MANAGED_KEYS, SOURCE_ACCESS_VALUES, SOURCE_IMPORT_KIND_VALUES, SOURCE_IMPORT_STATUS_VALUES, SOURCE_INTAKE_OUTCOME_VALUES, SOURCE_ROUTE_VALUES, SOURCE_STATUS_VALUES, SOURCE_TYPE_VALUES, ScoutProfileCreateSchema, ScoutProfileSchema, ScoutProfileUpdateSchema, ScoutRatingInputSchema, ScoutRatingSchema, ScoutSelfUpdateSchema, ScoutStatus, ScraperCreateSchema, ScraperMetricCreateSchema, ScraperMetricSchema, ScraperMetricUpdateSchema, ScraperSchema, ScraperStatus, ScraperUpdateSchema, SoftDeleteSchema, SourceAccess, SourceCreateSchema, SourceImportCreateSchema, SourceImportKind, SourceImportRowErrorSchema, SourceImportSchema, SourceImportStatus, SourceImportSummarySchema, SourceImportUpdateSchema, SourceIntakeBodySchema, SourceIntakeCandidateSchema, SourceIntakeOutcome, SourceIntakeResponseSchema, SourceIntakeResultSchema, SourceRatingSchema, SourceResultCardSchema, SourceRoute, SourceSchema, SourceStatus, SourceType, SourceUpdateSchema, SourceVisitBodySchema, SourceVisitResponseSchema, SpecialAccessSchema, SystemRecommendationInputSchema, SystemRecommendationSchema, TASK_KIND_VALUES, TASK_ORIGIN_VALUES, TASK_STATUS_VALUES, TaskCreateSchema, TaskCriteriaSchema, TaskKind, TaskOrigin, TaskSchema, TaskStatus, TaskTargetSchema, TaskUpdateSchema, TimeZone, TimestampsSchema, VETTING_STATUS_VALUES, VettingStatus, isHttpUrl };
1273
+ export { ACCESS_ISSUE_VALUES, AGENT_CARD_KIND_VALUES, AGENT_ERROR_CODE_VALUES, AGENT_MESSAGE_KIND_VALUES, AGENT_MESSAGE_ROLE_VALUES, AGENT_ROLE_VALUES, AGENT_SESSION_MODE_VALUES, AGENT_SESSION_STATUS_VALUES, AGENT_SOURCE_OUTCOME_VALUES, ASSIGNEE_TYPE_VALUES, ASSIGNMENT_SOURCE_VALUES, ASSIGNMENT_STATUS_VALUES, AccessIssue, AgentActiveSessionResponseSchema, AgentAssignmentItemSchema, AgentAssignmentVersionSchema, AgentAssignmentVersionsResponseSchema, AgentAssignmentsResponseSchema, AgentCaptureFieldsSchema, AgentCaptureResponseSchema, AgentCardKind, AgentCardSchema, AgentErrorCode, AgentErrorSchema, AgentMeSchema, AgentMessageCreateSchema, AgentMessageKind, AgentMessageRole, AgentMessageSchema, AgentMessageViewSchema, AgentMessagesQuerySchema, AgentMessagesResponseSchema, AgentOrgRefSchema, AgentReplyBodySchema, AgentRole, AgentSessionBudgetSchema, AgentSessionCreateSchema, AgentSessionMode, AgentSessionResponseSchema, AgentSessionSchema, AgentSessionStartBodySchema, AgentSessionStartResponseSchema, AgentSessionStatsSchema, AgentSessionStatus, AgentSessionUpdateSchema, AgentSessionViewSchema, AgentSourceOutcome, AgentStreamEventSchema, AgentTaskCriteriaSchema, AgentTaskSchema, AgentTaskSourceSchema, AgentTaskTargetSchema, AnalystProfileSchema, AnalystProfileUpdateSchema, ApiErrorSchema, AssigneeLoadSchema, AssigneeType, AssignmentCreateSchema, AssignmentSchema, AssignmentSource, AssignmentStatus, AssignmentUpdateSchema, AuditLogCreateSchema, AuditLogSchema, AuditLogUpdateSchema, AuditTargetSchema, AvailabilityWindowSchema, BlobRefSchema, CAPTURE_DOM_STATUS_VALUES, CAPTURE_STATUS_VALUES, CAPTURE_WINDOW_MODE_VALUES, COLLECTIONS, COLLECTOR_TYPE_VALUES, CaptureCreateSchema, CaptureDomSnapshotSchema, CaptureDomStatus, CaptureDomSummarySchema, CapturePromptCardSchema, CaptureRegionSchema, CaptureSchema, CaptureStatus, CaptureThumbCardSchema, CaptureWindowMode, CaptureWindowSchema, ClerkOrgId, ClerkUserId, CollectorSchema, CollectorType, ConnectionString, CoverageWindowSchema, DATABASE_COLLECTION_VALUES, DATABASE_STATUS_VALUES, DEFAULT_ANALYST_TASK_LIMIT, DEFAULT_SCOUT_TASK_LIMIT, DEPLOYMENT_KIND_VALUES, DEPLOYMENT_STATUS_VALUES, DISCOVERED_BY_TYPE_VALUES, DataItemContentSchema, DataItemCreateSchema, DataItemEntitySchema, DataItemSchema, DataItemUpdateSchema, DatabaseCollection, DatabaseCreateSchema, DatabaseId, DatabaseName, DatabaseSchema, DatabaseStatus, DatabaseUpdateSchema, DeploymentCreateSchema, DeploymentKind, DeploymentSchema, DeploymentStatus, DeploymentStepSchema, DeploymentUpdateSchema, DiscoveredBySchema, DiscoveredByType, DomBlockSchema, DomLinkSchema, DomRectSchema, Email, GLOBAL_LOAD_SCOPE, GeoSchema, HHmm, HOURS_LOG_SOURCE_VALUES, HoursLogCreateSchema, HoursLogSchema, HoursLogSource, HoursLogUpdateSchema, HoursProposalCardSchema, INTERNAL_ERROR_CODE_VALUES, InternalErrorCode, ItemResultCardSchema, LLM_CAPABILITY_VALUES, LLM_OUTCOME_VALUES, LLM_PROVIDER_VALUES, LanguageCode, LlmCallCreateSchema, LlmCallSchema, LlmCapability, LlmOutcome, LlmProvider, LlmUsageSchema, LoadScope, MAX_AGENT_MESSAGE_TEXT_LENGTH, MAX_CAPTURE_WINDOW_DAYS, MAX_RATING_COMMENT_LENGTH, MAX_SOURCE_IMPORT_ROW_ERRORS, MAX_SOURCE_INTAKE_CANDIDATES, MISSION_PRIORITY_VALUES, MISSION_STATUS_VALUES, MONITOR_TASK_MAX_SOURCES, MatchingFieldsSchema, MissionCreateSchema, MissionPriority, MissionSchema, MissionStatus, MissionUpdateSchema, ObjectIdString, OpenLinkCardSchema, OrgSettingsSchema, OrgSettingsUpdateSchema, OverdueLevelSchema, PLATFORM_VALUES, PaginatedSchema, PaginationQuerySchema, Platform, PlatformAccessSchema, PriorityAlertBodySchema, PriorityAlertResponseSchema, QuickRepliesCardSchema, QuickReplyOptionSchema, RATER_TYPE_VALUES, REGION_MODE_VALUES, RaterType, RatingScore, RatingSummarySchema, RegionMode, SCOUT_STATUS_VALUES, SCRAPER_STATUS_VALUES, SERVER_MANAGED_KEYS, SOURCE_ACCESS_VALUES, SOURCE_IMPORT_KIND_VALUES, SOURCE_IMPORT_STATUS_VALUES, SOURCE_INTAKE_OUTCOME_VALUES, SOURCE_ROUTE_VALUES, SOURCE_STATUS_VALUES, SOURCE_TYPE_VALUES, ScoutProfileCreateSchema, ScoutProfileSchema, ScoutProfileUpdateSchema, ScoutRatingInputSchema, ScoutRatingSchema, ScoutSelfUpdateSchema, ScoutStatus, ScraperCreateSchema, ScraperMetricCreateSchema, ScraperMetricSchema, ScraperMetricUpdateSchema, ScraperSchema, ScraperStatus, ScraperUpdateSchema, SoftDeleteSchema, SourceAccess, SourceCreateSchema, SourceDiscoverySchema, SourceImportCreateSchema, SourceImportKind, SourceImportRowErrorSchema, SourceImportSchema, SourceImportStatus, SourceImportSummarySchema, SourceImportUpdateSchema, SourceIntakeBodySchema, SourceIntakeCandidateSchema, SourceIntakeOutcome, SourceIntakeResponseSchema, SourceIntakeResultSchema, SourceRatingSchema, SourceResultCardSchema, SourceRoute, SourceSchema, SourceStatus, SourceType, SourceUpdateSchema, SourceVisitBodySchema, SourceVisitResponseSchema, SpecialAccessSchema, SystemRecommendationInputSchema, SystemRecommendationSchema, TASK_KIND_VALUES, TASK_ORIGIN_VALUES, TASK_STATUS_VALUES, TaskCreateSchema, TaskCriteriaSchema, TaskKind, TaskOrigin, TaskSchema, TaskStatus, TaskTargetSchema, TaskUpdateSchema, TimeZone, TimestampsSchema, URGENCY_FACTOR, VETTING_STATUS_VALUES, VISIT_INTERVAL_MAX_MS, VISIT_INTERVAL_MIN_MS, VettingStatus, baseVisitInterval, clampInterval, effectiveDueAt, effectiveInterval, isHttpUrl, overdueLevel, urgencyFactor };
1191
1274
  //# sourceMappingURL=index.js.map
1192
1275
  //# sourceMappingURL=index.js.map