@semiont/jobs 0.5.4 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -42
- package/dist/index.d.ts +578 -20
- package/dist/index.js +224 -430
- package/dist/index.js.map +1 -1
- package/dist/worker-main.d.ts +2 -22
- package/dist/worker-main.js +1425 -1485
- package/dist/worker-main.js.map +1 -1
- package/package.json +10 -4
- package/dist/fs-job-queue.d.ts +0 -79
- package/dist/fs-job-queue.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/job-claim-adapter.d.ts +0 -76
- package/dist/job-claim-adapter.d.ts.map +0 -1
- package/dist/job-queue-interface.d.ts +0 -19
- package/dist/job-queue-interface.d.ts.map +0 -1
- package/dist/job-queue-state-unit.d.ts +0 -26
- package/dist/job-queue-state-unit.d.ts.map +0 -1
- package/dist/job-worker.d.ts +0 -67
- package/dist/job-worker.d.ts.map +0 -1
- package/dist/processors.d.ts +0 -41
- package/dist/processors.d.ts.map +0 -1
- package/dist/types.d.ts +0 -319
- package/dist/types.d.ts.map +0 -1
- package/dist/worker-main.d.ts.map +0 -1
- package/dist/worker-process.d.ts +0 -47
- package/dist/worker-process.d.ts.map +0 -1
- package/dist/workers/annotation-detection.d.ts +0 -61
- package/dist/workers/annotation-detection.d.ts.map +0 -1
- package/dist/workers/detection/entity-extractor.d.ts +0 -42
- package/dist/workers/detection/entity-extractor.d.ts.map +0 -1
- package/dist/workers/detection/motivation-parsers.d.ts +0 -116
- package/dist/workers/detection/motivation-parsers.d.ts.map +0 -1
- package/dist/workers/detection/motivation-prompts.d.ts +0 -57
- package/dist/workers/detection/motivation-prompts.d.ts.map +0 -1
- package/dist/workers/generation/resource-generation.d.ts +0 -23
- package/dist/workers/generation/resource-generation.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Job queue, worker infrastructure, and annotation workers for [Semiont](https://g
|
|
|
10
10
|
|
|
11
11
|
## Architecture Context
|
|
12
12
|
|
|
13
|
-
Workers run in a separate
|
|
13
|
+
Workers run in a separate process and connect to the Knowledge System (KS) over HTTP/SSE using a `SemiontSession` (from `@semiont/sdk`) driven by a `JobClaimAdapter`. Workers receive job assignments via an SSE `job:queued` subscription, claim jobs atomically, and emit domain events back to the KS via `session.client.transport.emit(...)`. The KS ingests these events onto its EventBus for SSE delivery to the frontend.
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -19,20 +19,24 @@ npm install @semiont/jobs
|
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
**Dependencies:**
|
|
22
|
-
- `@semiont/core` — Core types, EventBus
|
|
23
|
-
- `@semiont/
|
|
22
|
+
- `@semiont/core` — Core types, `SemiontProject`, EventBus
|
|
23
|
+
- `@semiont/sdk` — `SemiontSession`, `JobClaimAdapter` (worker process)
|
|
24
|
+
- `@semiont/api-client` — HTTP transport, OpenAPI types
|
|
24
25
|
- `@semiont/inference` — InferenceClient for AI operations
|
|
26
|
+
- `@semiont/content` — Content storage URI derivation
|
|
27
|
+
- `@semiont/observability` — Spans and job-outcome metrics
|
|
25
28
|
|
|
26
29
|
## Quick Start
|
|
27
30
|
|
|
28
31
|
```typescript
|
|
29
|
-
import {
|
|
30
|
-
import { EventBus, userId, resourceId, annotationId } from '@semiont/core';
|
|
31
|
-
import {
|
|
32
|
+
import { FsJobQueue, type PendingJob, type GenerationParams } from '@semiont/jobs';
|
|
33
|
+
import { EventBus, userId, resourceId, annotationId, jobId } from '@semiont/core';
|
|
34
|
+
import { SemiontProject } from '@semiont/core/node';
|
|
32
35
|
|
|
33
|
-
// Initialize
|
|
36
|
+
// Initialize — jobs are stored under project.jobsDir
|
|
34
37
|
const eventBus = new EventBus();
|
|
35
|
-
const
|
|
38
|
+
const project = new SemiontProject('/path/to/project');
|
|
39
|
+
const jobQueue = new FsJobQueue(project, logger, eventBus);
|
|
36
40
|
await jobQueue.initialize();
|
|
37
41
|
|
|
38
42
|
// Create a job
|
|
@@ -97,45 +101,30 @@ The `userName`, `userEmail`, and `userDomain` fields are used by workers to buil
|
|
|
97
101
|
|
|
98
102
|
## Annotation Workers
|
|
99
103
|
|
|
100
|
-
|
|
104
|
+
The worker process (`worker-main.ts` → `startWorkerProcess` in `worker-process.ts`) claims jobs over the bus via a `JobClaimAdapter` and dispatches by `jobType` to a processor function. There are no per-type worker classes; each job type maps to one `process*Job` function:
|
|
101
105
|
|
|
102
|
-
|
|
|
103
|
-
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
109
|
-
| `
|
|
106
|
+
| Job Type | Processor |
|
|
107
|
+
|----------|-----------|
|
|
108
|
+
| `reference-annotation` | `processReferenceJob` |
|
|
109
|
+
| `generation` | `processGenerationJob` |
|
|
110
|
+
| `highlight-annotation` | `processHighlightJob` |
|
|
111
|
+
| `assessment-annotation` | `processAssessmentJob` |
|
|
112
|
+
| `comment-annotation` | `processCommentJob` |
|
|
113
|
+
| `tag-annotation` | `processTagJob` |
|
|
110
114
|
|
|
111
|
-
|
|
115
|
+
Detection logic lives in the `AnnotationDetection` class (`src/workers/annotation-detection.ts`); generation synthesis in `generateResourceFromTopic()` (`src/workers/generation/resource-generation.ts`). Each processor fetches content via `session.client.browse.resourceContent(resourceId)`.
|
|
112
116
|
|
|
113
|
-
|
|
117
|
+
Workers emit bus events via `session.client.transport.emit('mark:create' | 'job:start' | 'job:report-progress' | 'job:complete' | 'job:fail', payload)` — the Stower actor in @semiont/make-meaning handles persistence.
|
|
114
118
|
|
|
115
|
-
|
|
116
|
-
import { JobWorker, type AnyJob } from '@semiont/jobs';
|
|
117
|
-
import type { Logger } from '@semiont/core';
|
|
118
|
-
|
|
119
|
-
class MyWorker extends JobWorker {
|
|
120
|
-
constructor(jobQueue: JobQueue, logger: Logger) {
|
|
121
|
-
super(jobQueue, 1000, 5000, logger);
|
|
122
|
-
// ^^^^ ^^^^
|
|
123
|
-
// poll error backoff
|
|
124
|
-
}
|
|
119
|
+
## Adding a Job Type
|
|
125
120
|
|
|
126
|
-
|
|
127
|
-
return 'MyWorker';
|
|
128
|
-
}
|
|
121
|
+
Workers are not subclassed. To add a job type:
|
|
129
122
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
123
|
+
1. Add the new `JobType` and its params/result/progress types in `src/types.ts`.
|
|
124
|
+
2. Add a `process*Job` function in `src/processors.ts` that runs the inference and returns the annotations/result.
|
|
125
|
+
3. Dispatch the new `jobType` to that processor in `handleJobInner()` in `src/worker-process.ts`.
|
|
133
126
|
|
|
134
|
-
|
|
135
|
-
// Your processing logic — return result object
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
```
|
|
127
|
+
Processors are transport-agnostic: they take content, an `InferenceClient`, the job params, the user id, the `generator` (W3C SoftwareAgent), and an `onProgress` callback, and return annotations plus a result. The worker process handles claiming, content fetching, and lifecycle event emission.
|
|
139
128
|
|
|
140
129
|
## Discriminated Unions
|
|
141
130
|
|
|
@@ -182,7 +171,8 @@ Apache-2.0
|
|
|
182
171
|
|
|
183
172
|
## Related Packages
|
|
184
173
|
|
|
185
|
-
- [`@semiont/core`](../core/) — Domain types, EventBus
|
|
186
|
-
- [`@semiont/
|
|
174
|
+
- [`@semiont/core`](../core/) — Domain types, `SemiontProject`, EventBus
|
|
175
|
+
- [`@semiont/sdk`](../sdk/) — `SemiontSession`, `JobClaimAdapter`
|
|
176
|
+
- [`@semiont/api-client`](../api-client/) — HTTP transport, OpenAPI types
|
|
187
177
|
- [`@semiont/inference`](../inference/) — AI inference client
|
|
188
178
|
- [`@semiont/make-meaning`](../make-meaning/) — Actor model, Knowledge Base, service orchestration
|