@semiont/jobs 0.5.4 → 0.5.5

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.
Files changed (33) hide show
  1. package/dist/index.d.ts +644 -20
  2. package/dist/worker-main.d.ts +2 -22
  3. package/dist/worker-main.js +1197 -1197
  4. package/dist/worker-main.js.map +1 -1
  5. package/package.json +4 -2
  6. package/dist/fs-job-queue.d.ts +0 -79
  7. package/dist/fs-job-queue.d.ts.map +0 -1
  8. package/dist/index.d.ts.map +0 -1
  9. package/dist/job-claim-adapter.d.ts +0 -76
  10. package/dist/job-claim-adapter.d.ts.map +0 -1
  11. package/dist/job-queue-interface.d.ts +0 -19
  12. package/dist/job-queue-interface.d.ts.map +0 -1
  13. package/dist/job-queue-state-unit.d.ts +0 -26
  14. package/dist/job-queue-state-unit.d.ts.map +0 -1
  15. package/dist/job-worker.d.ts +0 -67
  16. package/dist/job-worker.d.ts.map +0 -1
  17. package/dist/processors.d.ts +0 -41
  18. package/dist/processors.d.ts.map +0 -1
  19. package/dist/types.d.ts +0 -319
  20. package/dist/types.d.ts.map +0 -1
  21. package/dist/worker-main.d.ts.map +0 -1
  22. package/dist/worker-process.d.ts +0 -47
  23. package/dist/worker-process.d.ts.map +0 -1
  24. package/dist/workers/annotation-detection.d.ts +0 -61
  25. package/dist/workers/annotation-detection.d.ts.map +0 -1
  26. package/dist/workers/detection/entity-extractor.d.ts +0 -42
  27. package/dist/workers/detection/entity-extractor.d.ts.map +0 -1
  28. package/dist/workers/detection/motivation-parsers.d.ts +0 -116
  29. package/dist/workers/detection/motivation-parsers.d.ts.map +0 -1
  30. package/dist/workers/detection/motivation-prompts.d.ts +0 -57
  31. package/dist/workers/detection/motivation-prompts.d.ts.map +0 -1
  32. package/dist/workers/generation/resource-generation.d.ts +0 -23
  33. package/dist/workers/generation/resource-generation.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semiont/jobs",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "type": "module",
5
5
  "description": "Filesystem-based job queue and worker infrastructure",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  "README.md"
21
21
  ],
22
22
  "scripts": {
23
- "build": "npm run typecheck && tsup && tsc -p tsconfig.build.json",
23
+ "build": "npm run typecheck && tsup && tsc -p tsconfig.build.json && rollup -c rollup.dts.config.mjs && rm -rf dist-types",
24
24
  "typecheck": "tsc --noEmit",
25
25
  "test": "vitest",
26
26
  "test:coverage": "vitest run --coverage"
@@ -36,6 +36,8 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@vitest/coverage-v8": "^4.1.0",
39
+ "rollup": "^4.60.3",
40
+ "rollup-plugin-dts": "^6.4.1",
39
41
  "tsup": "^8.0.1",
40
42
  "typescript": "^6.0.2"
41
43
  },
@@ -1,79 +0,0 @@
1
- /**
2
- * Job Queue Manager
3
- *
4
- * Filesystem-based job queue with atomic operations.
5
- * Jobs are stored in directories by status for easy polling.
6
- */
7
- import type { AnyJob, JobStatus, JobQueryFilters } from './types';
8
- import type { SemiontProject } from '@semiont/core/node';
9
- import type { JobId, Logger, EventBus } from '@semiont/core';
10
- import type { JobQueue } from './job-queue-interface';
11
- export declare class FsJobQueue implements JobQueue {
12
- private eventBus?;
13
- private jobsDir;
14
- private logger;
15
- private pendingQueue;
16
- private watcher;
17
- private loadDebounceTimer;
18
- constructor(project: SemiontProject, logger: Logger, eventBus?: EventBus | undefined);
19
- /**
20
- * Initialize job queue directories, load pending jobs, and start fs.watch
21
- */
22
- initialize(): Promise<void>;
23
- /**
24
- * Clean up watcher
25
- */
26
- destroy(): void;
27
- /**
28
- * Load pending jobs from disk into in-memory queue
29
- */
30
- private loadPendingJobs;
31
- /**
32
- * Debounced version of loadPendingJobs — fs.watch can fire rapidly
33
- */
34
- private debouncedLoadPendingJobs;
35
- /**
36
- * Create a new job
37
- */
38
- createJob(job: AnyJob): Promise<void>;
39
- /**
40
- * Get a job by ID (searches all status directories)
41
- */
42
- getJob(jobId: JobId): Promise<AnyJob | null>;
43
- /**
44
- * Update a job (atomic: delete old, write new)
45
- */
46
- updateJob(job: AnyJob, oldStatus?: JobStatus): Promise<void>;
47
- /**
48
- * Poll for next pending job (FIFO) from in-memory queue.
49
- * If a predicate is provided, returns the first matching job (skipping non-matching ones).
50
- */
51
- pollNextPendingJob(predicate?: (job: AnyJob) => boolean): Promise<AnyJob | null>;
52
- /**
53
- * List jobs with filters
54
- */
55
- listJobs(filters?: JobQueryFilters): Promise<AnyJob[]>;
56
- /**
57
- * Cancel a job
58
- */
59
- cancelJob(jobId: JobId): Promise<boolean>;
60
- /**
61
- * Clean up old completed/failed jobs (older than retention period)
62
- */
63
- cleanupOldJobs(retentionHours?: number): Promise<number>;
64
- /**
65
- * Get job file path
66
- */
67
- private getJobPath;
68
- /**
69
- * Get statistics about the queue
70
- */
71
- getStats(): Promise<{
72
- pending: number;
73
- running: number;
74
- complete: number;
75
- failed: number;
76
- cancelled: number;
77
- }>;
78
- }
79
- //# sourceMappingURL=fs-job-queue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs-job-queue.d.ts","sourceRoot":"","sources":["../src/fs-job-queue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAgB,MAAM,SAAS,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,qBAAa,UAAW,YAAW,QAAQ;IAWvC,OAAO,CAAC,QAAQ,CAAC;IAVnB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,YAAY,CAAgB;IACp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0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,YAAY,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,YAAY,EACV,OAAO,EACP,SAAS,EACT,WAAW,EACX,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EACf,MAAM,EACN,UAAU,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,YAAY,EACZ,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC"}
@@ -1,76 +0,0 @@
1
- /**
2
- * Job Claim Adapter — worker-side job lifecycle glue on top of a
3
- * shared bus.
4
- *
5
- * Replaces the old `WorkerStateUnit`, which owned its own actor and
6
- * duplicated the SSE connection that `SemiontClient` already held.
7
- * Workers construct a `SemiontSession` normally (one actor, one
8
- * SSE connection) and use this adapter to attach job-claim behaviour
9
- * on top of the session's bus.
10
- *
11
- * The adapter is intentionally thin: it subscribes to `job:queued`,
12
- * claims jobs via the existing request-response protocol
13
- * (`job:claim` → `job:claimed` / `job:claim-failed`), and exposes
14
- * observables for job orchestration. It does **not** own the bus,
15
- * has no HTTP concerns, and has no modal state.
16
- *
17
- * The `bus` parameter is typed against the small `JobClaimBus`
18
- * interface below so the adapter is transport-neutral. HTTP workers
19
- * pass `(session.client.transport as HttpTransport).actor`; an
20
- * in-process worker could pass a shim wrapping `client.bus`.
21
- */
22
- import { Observable } from 'rxjs';
23
- import type { WorkerBus } from '@semiont/sdk';
24
- export interface JobAssignment {
25
- jobId: string;
26
- type: string;
27
- resourceId: string;
28
- }
29
- export interface ActiveJob {
30
- jobId: string;
31
- type: string;
32
- resourceId: string;
33
- userId: string;
34
- params: Record<string, unknown>;
35
- }
36
- export interface JobClaimAdapterOptions {
37
- /** Shared bus (typically the session's HTTP actor or an in-process bus shim). */
38
- bus: WorkerBus;
39
- /**
40
- * Job types this worker can process. Jobs of other types that
41
- * arrive on `job:queued` are ignored. Empty array = accept any.
42
- */
43
- jobTypes: string[];
44
- }
45
- export interface JobClaimAdapter {
46
- /** Currently-claimed job, or null when idle. */
47
- readonly activeJob$: Observable<ActiveJob | null>;
48
- /** True while a claim is in flight or a job is being processed. */
49
- readonly isProcessing$: Observable<boolean>;
50
- /** Monotonically-incrementing count of successfully-completed jobs. */
51
- readonly jobsCompleted$: Observable<number>;
52
- /** Stream of job failures (including claim-failed and processing errors). */
53
- readonly errors$: Observable<{
54
- jobId: string;
55
- error: string;
56
- }>;
57
- /**
58
- * Subscribe to `job:queued` events (adding the channel to the actor
59
- * if not already subscribed) and begin claiming matching jobs.
60
- * Idempotent — calling `start()` twice is a no-op.
61
- */
62
- start(): void;
63
- /** Stop claiming new jobs. Does not cancel an in-flight job. */
64
- stop(): void;
65
- /** Signal successful completion of `activeJob$`. */
66
- completeJob(): void;
67
- /** Signal failure of `activeJob$`. Emits on `errors$`. */
68
- failJob(jobId: string, error: string): void;
69
- /** Release observables. Does not dispose the shared bus. */
70
- dispose(): void;
71
- }
72
- /**
73
- * Attach job-claim behaviour to a shared bus.
74
- */
75
- export declare function createJobClaimAdapter(options: JobClaimAdapterOptions): JobClaimAdapter;
76
- //# sourceMappingURL=job-claim-adapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"job-claim-adapter.d.ts","sourceRoot":"","sources":["../src/job-claim-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAmB,UAAU,EAAW,MAAM,MAAM,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,iFAAiF;IACjF,GAAG,EAAE,SAAS,CAAC;IACf;;;OAGG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,gDAAgD;IAChD,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAClD,mEAAmE;IACnE,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC5C,uEAAuE;IACvE,QAAQ,CAAC,cAAc,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAC5C,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE/D;;;;OAIG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd,gEAAgE;IAChE,IAAI,IAAI,IAAI,CAAC;IAEb,oDAAoD;IACpD,WAAW,IAAI,IAAI,CAAC;IAEpB,0DAA0D;IAC1D,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5C,4DAA4D;IAC5D,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CA+GtF"}
@@ -1,19 +0,0 @@
1
- import type { AnyJob, JobStatus } from './types';
2
- import type { JobId } from '@semiont/core';
3
- export interface JobQueue {
4
- initialize(): Promise<void>;
5
- destroy(): void;
6
- createJob(job: AnyJob): Promise<void>;
7
- getJob(jobId: JobId): Promise<AnyJob | null>;
8
- updateJob(job: AnyJob, oldStatus?: JobStatus): Promise<void>;
9
- pollNextPendingJob(predicate?: (job: AnyJob) => boolean): Promise<AnyJob | null>;
10
- cancelJob(jobId: JobId): Promise<boolean>;
11
- getStats(): Promise<{
12
- pending: number;
13
- running: number;
14
- complete: number;
15
- failed: number;
16
- cancelled: number;
17
- }>;
18
- }
19
- //# sourceMappingURL=job-queue-interface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"job-queue-interface.d.ts","sourceRoot":"","sources":["../src/job-queue-interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,WAAW,QAAQ;IACvB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC;IAChB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACjF,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,QAAQ,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChH"}
@@ -1,26 +0,0 @@
1
- import { type Observable } from 'rxjs';
2
- import type { SemiontClient, StateUnit } from '@semiont/sdk';
3
- export interface Job {
4
- jobId: string;
5
- type: string;
6
- status: string;
7
- resourceId: string;
8
- /** DID of the user who initiated the job (audit). */
9
- userId: string;
10
- created: string;
11
- startedAt?: string;
12
- completedAt?: string;
13
- error?: string;
14
- progress?: Record<string, unknown>;
15
- result?: Record<string, unknown>;
16
- }
17
- export interface JobQueueStateUnit extends StateUnit {
18
- jobs$: Observable<Job[]>;
19
- pendingByType$: Observable<Map<string, number>>;
20
- runningJobs$: Observable<Job[]>;
21
- jobCreated$: Observable<Job>;
22
- jobCompleted$: Observable<Job>;
23
- jobFailed$: Observable<Job>;
24
- }
25
- export declare function createJobQueueStateUnit(client: SemiontClient): JobQueueStateUnit;
26
- //# sourceMappingURL=job-queue-state-unit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"job-queue-state-unit.d.ts","sourceRoot":"","sources":["../src/job-queue-state-unit.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,UAAU,EAAO,MAAM,MAAM,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE7D,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,iBAAkB,SAAQ,SAAS;IAClD,KAAK,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC;IACzB,cAAc,EAAE,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,YAAY,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC;IAChC,WAAW,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,aAAa,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;CAC7B;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,aAAa,GAAG,iBAAiB,CAoGhF"}
@@ -1,67 +0,0 @@
1
- /**
2
- * Job Worker Base Class
3
- *
4
- * Abstract worker that polls the job queue and processes jobs.
5
- * Subclasses implement specific job processing logic.
6
- */
7
- import type { AnyJob, RunningJob } from './types';
8
- import type { JobQueue } from './job-queue-interface';
9
- import type { Logger } from '@semiont/core';
10
- export declare abstract class JobWorker {
11
- private running;
12
- private currentJob;
13
- private pollIntervalMs;
14
- private errorBackoffMs;
15
- protected jobQueue: JobQueue;
16
- protected logger: Logger;
17
- constructor(jobQueue: JobQueue, pollIntervalMs: number | undefined, errorBackoffMs: number | undefined, logger: Logger);
18
- /**
19
- * Start the worker (polls queue in loop)
20
- */
21
- start(): Promise<void>;
22
- /**
23
- * Stop the worker (graceful shutdown)
24
- */
25
- stop(): Promise<void>;
26
- /**
27
- * Poll for next job to process
28
- */
29
- private pollNextJob;
30
- /**
31
- * Process a job (handles state transitions and error handling)
32
- */
33
- private processJob;
34
- /**
35
- * Handle job failure (retry or move to failed)
36
- */
37
- protected handleJobFailure(job: AnyJob, error: any): Promise<void>;
38
- /**
39
- * Update job progress (best-effort, doesn't throw)
40
- */
41
- protected updateJobProgress(job: AnyJob): Promise<void>;
42
- /**
43
- * Sleep utility
44
- */
45
- protected sleep(ms: number): Promise<void>;
46
- /**
47
- * Emit completion event (optional hook for subclasses)
48
- * Override this to emit job-specific completion events (e.g., job.completed)
49
- */
50
- protected emitCompletionEvent(_job: RunningJob<any, any>, _result: any): Promise<void>;
51
- /**
52
- * Get worker name (for logging)
53
- */
54
- protected abstract getWorkerName(): string;
55
- /**
56
- * Check if this worker can process the given job
57
- */
58
- protected abstract canProcessJob(job: AnyJob): boolean;
59
- /**
60
- * Execute the job (job-specific logic)
61
- * This is where the actual work happens
62
- * Return the result object (or void for jobs without results)
63
- * Throw an error to trigger retry logic
64
- */
65
- protected abstract executeJob(job: AnyJob): Promise<any>;
66
- }
67
- //# sourceMappingURL=job-worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"job-worker.d.ts","sourceRoot":"","sources":["../src/job-worker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,UA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;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CACzD"}
@@ -1,41 +0,0 @@
1
- /**
2
- * Job Processors — extracted from JobWorker subclasses
3
- *
4
- * Pure functions that take content + inference client + params,
5
- * report progress via callback, and return annotations + results.
6
- *
7
- * No EventBus, no JobQueue, no side effects except calling inference.
8
- * Two callers:
9
- * 1. In-process JobWorker subclasses (existing path)
10
- * 2. Remote WorkerStateUnit via worker-process.ts (new path)
11
- */
12
- import { type Logger, type components } from '@semiont/core';
13
- import type { InferenceClient } from '@semiont/inference';
14
- import type { HighlightDetectionParams, CommentDetectionParams, AssessmentDetectionParams, DetectionParams, TagDetectionParams, GenerationParams, HighlightDetectionResult, CommentDetectionResult, AssessmentDetectionResult, DetectionResult, TagDetectionResult, GenerationResult } from './types';
15
- type Agent = components['schemas']['Agent'];
16
- /**
17
- * Progress callback. The three positional args satisfy the minimum
18
- * `JobProgress` required fields (`percentage`, `message`, `stage`).
19
- * The fourth optional arg carries job-type-specific fields
20
- * (`currentEntityType`, `completedEntityTypes`, `requestParams`, etc.)
21
- * that the progress UI renders.
22
- */
23
- export type OnProgress = (percentage: number, message: string, stage: string, extra?: Partial<JobProgress>) => void;
24
- type JobProgress = components['schemas']['JobProgress'];
25
- export interface ProcessorResult<R> {
26
- annotations: Record<string, unknown>[];
27
- result: R;
28
- }
29
- export declare function processHighlightJob(content: string, inferenceClient: InferenceClient, params: HighlightDetectionParams, userId: string, generator: Agent, onProgress: OnProgress): Promise<ProcessorResult<HighlightDetectionResult>>;
30
- export declare function processCommentJob(content: string, inferenceClient: InferenceClient, params: CommentDetectionParams, userId: string, generator: Agent, onProgress: OnProgress): Promise<ProcessorResult<CommentDetectionResult>>;
31
- export declare function processAssessmentJob(content: string, inferenceClient: InferenceClient, params: AssessmentDetectionParams, userId: string, generator: Agent, onProgress: OnProgress): Promise<ProcessorResult<AssessmentDetectionResult>>;
32
- export declare function processReferenceJob(content: string, inferenceClient: InferenceClient, params: DetectionParams, userId: string, generator: Agent, onProgress: OnProgress, logger: Logger): Promise<ProcessorResult<DetectionResult>>;
33
- export declare function processTagJob(content: string, inferenceClient: InferenceClient, params: TagDetectionParams, userId: string, generator: Agent, onProgress: OnProgress): Promise<ProcessorResult<TagDetectionResult>>;
34
- export declare function processGenerationJob(inferenceClient: InferenceClient, params: GenerationParams, onProgress: OnProgress, logger: Logger): Promise<{
35
- content: string;
36
- title: string;
37
- format: string;
38
- result: GenerationResult;
39
- }>;
40
- export {};
41
- //# sourceMappingURL=processors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"processors.d.ts","sourceRoot":"","sources":["../src/processors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EAAc,KAAK,MAAM,EAAmB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,KAAK,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,KACzB,IAAI,CAAC;AAEV,KAAK,WAAW,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,CAAC;AAExD,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC,MAAM,EA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