@semiont/jobs 0.5.26 → 0.5.28
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 +13 -12
- package/dist/index.d.ts +35 -72
- package/dist/index.js +165 -96
- package/dist/index.js.map +1 -1
- package/dist/worker-main.js +198 -115
- package/dist/worker-main.js.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -30,8 +30,8 @@ npm install @semiont/jobs
|
|
|
30
30
|
## Quick Start
|
|
31
31
|
|
|
32
32
|
```typescript
|
|
33
|
-
import { FsJobQueue, type PendingJob, type
|
|
34
|
-
import { EventBus, userId, resourceId,
|
|
33
|
+
import { FsJobQueue, type PendingJob, type DetectionParams } from '@semiont/jobs';
|
|
34
|
+
import { EventBus, userId, resourceId, jobId } from '@semiont/core';
|
|
35
35
|
import { SemiontProject } from '@semiont/core/node';
|
|
36
36
|
|
|
37
37
|
// Initialize — jobs are stored under project.jobsDir
|
|
@@ -41,33 +41,34 @@ const jobQueue = new FsJobQueue(project, logger, eventBus);
|
|
|
41
41
|
await jobQueue.initialize();
|
|
42
42
|
|
|
43
43
|
// Create a job
|
|
44
|
-
const job: PendingJob<
|
|
44
|
+
const job: PendingJob<DetectionParams> = {
|
|
45
45
|
status: 'pending',
|
|
46
46
|
metadata: {
|
|
47
47
|
id: jobId('job-abc123'),
|
|
48
|
-
type: '
|
|
48
|
+
type: 'reference-annotation',
|
|
49
49
|
userId: userId('user@example.com'),
|
|
50
50
|
userName: 'Jane Doe',
|
|
51
51
|
userEmail: 'jane@example.com',
|
|
52
52
|
userDomain: 'example.com',
|
|
53
53
|
created: new Date().toISOString(),
|
|
54
54
|
retryCount: 0,
|
|
55
|
-
maxRetries:
|
|
55
|
+
maxRetries: 1,
|
|
56
56
|
},
|
|
57
57
|
params: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
sourceResourceName: 'Source Document',
|
|
61
|
-
annotation: { /* full W3C Annotation */ },
|
|
62
|
-
title: 'Generated Article',
|
|
63
|
-
prompt: 'Write about AI',
|
|
64
|
-
language: 'en-US',
|
|
58
|
+
resourceId: resourceId('doc-456'),
|
|
59
|
+
entityTypes: ['Person', 'Organization'],
|
|
65
60
|
},
|
|
66
61
|
};
|
|
67
62
|
|
|
68
63
|
await jobQueue.createJob(job);
|
|
69
64
|
```
|
|
70
65
|
|
|
66
|
+
Generation jobs are enqueued the same way, but their params are a
|
|
67
|
+
[`GenerationJobParams`](./docs/JobTypes.md#generation-generation) bag whose
|
|
68
|
+
`context` carries the anchor — writing one straight to the queue bypasses the
|
|
69
|
+
dispatcher that normally derives and stamps `resourceId` from
|
|
70
|
+
`context.focus`, so prefer `client.yield.fromContext(...)`.
|
|
71
|
+
|
|
71
72
|
## Job Types
|
|
72
73
|
|
|
73
74
|
```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JobId, UserId, ResourceId, EntityType,
|
|
1
|
+
import { JobId, UserId, ResourceId, EntityType, GenerationJobParams, TagSchema, Logger, EventBus, components, Annotation, SupportedMediaType, GatheredContext } from '@semiont/core';
|
|
2
2
|
import { SemiontProject } from '@semiont/core/node';
|
|
3
3
|
import { InferenceClient } from '@semiont/inference';
|
|
4
4
|
|
|
@@ -70,63 +70,6 @@ interface DetectionParams {
|
|
|
70
70
|
/** Source-resource locale — see locale conventions above. */
|
|
71
71
|
sourceLanguage?: string;
|
|
72
72
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Generation job parameters
|
|
75
|
-
*/
|
|
76
|
-
interface GenerationParams {
|
|
77
|
-
/**
|
|
78
|
-
* The unresolved reference an annotation-focus generation was triggered from.
|
|
79
|
-
* Absent for resource-focus generation (`yield.fromResource`). When present, the
|
|
80
|
-
* worker auto-binds the new resource to it; when absent, provenance is a minted
|
|
81
|
-
* source→derived reference annotation (Fork 2b).
|
|
82
|
-
*/
|
|
83
|
-
referenceId?: AnnotationId;
|
|
84
|
-
prompt?: string;
|
|
85
|
-
title?: string;
|
|
86
|
-
entityTypes?: EntityType[];
|
|
87
|
-
/** Annotation body locale — language the *generated resource* is written in. */
|
|
88
|
-
language?: string;
|
|
89
|
-
/**
|
|
90
|
-
* Source-resource locale — language of the resource being referenced.
|
|
91
|
-
* Used in the prompt so the LLM understands the embedded source-context
|
|
92
|
-
* snippet correctly when source ≠ target language.
|
|
93
|
-
*/
|
|
94
|
-
sourceLanguage?: string;
|
|
95
|
-
context?: GatheredContext;
|
|
96
|
-
temperature?: number;
|
|
97
|
-
maxTokens?: number;
|
|
98
|
-
storageUri?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Requested media type of the generated resource's content. Default `text/markdown`.
|
|
101
|
-
* The generation worker produces `text/markdown` and `text/plain`; any other value
|
|
102
|
-
* fails the job (no silent fallback) — Semiont is multi-modal at the core, but
|
|
103
|
-
* generation coverage is text-only for now and the gap is surfaced, not hidden.
|
|
104
|
-
*/
|
|
105
|
-
outputMediaType?: SupportedMediaType;
|
|
106
|
-
/**
|
|
107
|
-
* What the model is asked to DO — the prompt's framing verb. Canonical values map
|
|
108
|
-
* to tested framings; any other string is used verbatim as the framing instruction
|
|
109
|
-
* (loud degrade: the worker warns, never silently falls back to 'resource').
|
|
110
|
-
* Default 'resource'. See .plans/YIELD-STRUCTURE.md.
|
|
111
|
-
*/
|
|
112
|
-
task?: 'resource' | 'answer' | 'summary' | (string & {});
|
|
113
|
-
/**
|
|
114
|
-
* How the output is internally segmented — text-bearing shape, subordinate to
|
|
115
|
-
* `outputMediaType` (never its peer). Canonical values map to tested guidance; any
|
|
116
|
-
* other string becomes a freeform "Organize the output as: …" instruction (loud
|
|
117
|
-
* degrade). UNSET means NO structure directive is emitted — the task framing and
|
|
118
|
-
* the model determine shape. See .plans/YIELD-STRUCTURE.md D2/D5.
|
|
119
|
-
*/
|
|
120
|
-
structure?: 'prose' | 'sections' | 'chat' | (string & {});
|
|
121
|
-
/**
|
|
122
|
-
* Ask the model to cite: emit `[[<id>]]` transport tokens after each claim, using
|
|
123
|
-
* the ids the context embedding provides (CONTEXT-IDENTIFIERS). The worker
|
|
124
|
-
* validates each id against the embedded context (unknown ids are dropped
|
|
125
|
-
* loudly), strips the tokens from the stored content, and mints W3C linking
|
|
126
|
-
* annotations on the derived resource. See .plans/INLINE-CITATIONS.md.
|
|
127
|
-
*/
|
|
128
|
-
cite?: boolean;
|
|
129
|
-
}
|
|
130
73
|
/**
|
|
131
74
|
* Highlight detection job parameters
|
|
132
75
|
*/
|
|
@@ -186,7 +129,6 @@ interface TagDetectionParams {
|
|
|
186
129
|
interface DetectionProgress {
|
|
187
130
|
totalEntityTypes: number;
|
|
188
131
|
processedEntityTypes: number;
|
|
189
|
-
currentEntityType?: string;
|
|
190
132
|
entitiesFound: number;
|
|
191
133
|
entitiesEmitted: number;
|
|
192
134
|
}
|
|
@@ -194,6 +136,7 @@ interface DetectionProgress {
|
|
|
194
136
|
* Detection job result
|
|
195
137
|
*/
|
|
196
138
|
interface DetectionResult {
|
|
139
|
+
kind: 'reference-annotation';
|
|
197
140
|
totalFound: number;
|
|
198
141
|
totalEmitted: number;
|
|
199
142
|
errors: number;
|
|
@@ -211,8 +154,11 @@ interface YieldProgress {
|
|
|
211
154
|
* Generation job result
|
|
212
155
|
*/
|
|
213
156
|
interface GenerationResult {
|
|
157
|
+
kind: 'generation';
|
|
214
158
|
resourceId: ResourceId;
|
|
215
159
|
resourceName: string;
|
|
160
|
+
/** True when the model stopped at the maxTokens ceiling — the artifact is cut off, not complete (GENERATE-FROM-RESOURCE D6). */
|
|
161
|
+
truncated: boolean;
|
|
216
162
|
}
|
|
217
163
|
/**
|
|
218
164
|
* Highlight detection job progress
|
|
@@ -226,6 +172,7 @@ interface HighlightDetectionProgress {
|
|
|
226
172
|
* Highlight detection job result
|
|
227
173
|
*/
|
|
228
174
|
interface HighlightDetectionResult {
|
|
175
|
+
kind: 'highlight-annotation';
|
|
229
176
|
highlightsFound: number;
|
|
230
177
|
highlightsCreated: number;
|
|
231
178
|
}
|
|
@@ -241,6 +188,7 @@ interface AssessmentDetectionProgress {
|
|
|
241
188
|
* Assessment detection job result
|
|
242
189
|
*/
|
|
243
190
|
interface AssessmentDetectionResult {
|
|
191
|
+
kind: 'assessment-annotation';
|
|
244
192
|
assessmentsFound: number;
|
|
245
193
|
assessmentsCreated: number;
|
|
246
194
|
}
|
|
@@ -256,6 +204,7 @@ interface CommentDetectionProgress {
|
|
|
256
204
|
* Comment detection job result
|
|
257
205
|
*/
|
|
258
206
|
interface CommentDetectionResult {
|
|
207
|
+
kind: 'comment-annotation';
|
|
259
208
|
commentsFound: number;
|
|
260
209
|
commentsCreated: number;
|
|
261
210
|
}
|
|
@@ -274,6 +223,7 @@ interface TagDetectionProgress {
|
|
|
274
223
|
* Tag detection job result
|
|
275
224
|
*/
|
|
276
225
|
interface TagDetectionResult {
|
|
226
|
+
kind: 'tag-annotation';
|
|
277
227
|
tagsFound: number;
|
|
278
228
|
tagsCreated: number;
|
|
279
229
|
byCategory: Record<string, number>;
|
|
@@ -333,7 +283,7 @@ interface CancelledJob<P> {
|
|
|
333
283
|
*/
|
|
334
284
|
type Job<P, PG, R> = PendingJob<P> | RunningJob<P, PG> | CompleteJob<P, R> | FailedJob<P> | CancelledJob<P>;
|
|
335
285
|
type DetectionJob = Job<DetectionParams, DetectionProgress, DetectionResult>;
|
|
336
|
-
type GenerationJob = Job<
|
|
286
|
+
type GenerationJob = Job<GenerationJobParams, YieldProgress, GenerationResult>;
|
|
337
287
|
type HighlightDetectionJob = Job<HighlightDetectionParams, HighlightDetectionProgress, HighlightDetectionResult>;
|
|
338
288
|
type AssessmentDetectionJob = Job<AssessmentDetectionParams, AssessmentDetectionProgress, AssessmentDetectionResult>;
|
|
339
289
|
type CommentDetectionJob = Job<CommentDetectionParams, CommentDetectionProgress, CommentDetectionResult>;
|
|
@@ -541,14 +491,26 @@ type SpanMatch = {
|
|
|
541
491
|
*/
|
|
542
492
|
type BuildAnnotation = (motivation: Motivation, match: SpanMatch, body?: Annotation['body']) => Annotation;
|
|
543
493
|
/**
|
|
544
|
-
* Progress callback. The
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
* (`currentEntityType`, `completedEntityTypes`, `requestParams`, etc.)
|
|
494
|
+
* Progress callback. The two positional args are the required `JobProgress`
|
|
495
|
+
* fields (`percentage`, `message`). The third optional arg carries the
|
|
496
|
+
* job-type-specific fields (`completedEntityTypes`, `requestParams`, etc.)
|
|
548
497
|
* that the progress UI renders.
|
|
549
|
-
|
|
550
|
-
|
|
498
|
+
*
|
|
499
|
+
* Anything in `extra` describing the RUN rather than the moment must be passed
|
|
500
|
+
* on EVERY call: the client's `progress$` replaces its value per event, so a
|
|
501
|
+
* field sent once disappears on the next tick.
|
|
502
|
+
*
|
|
503
|
+
* `message` is a CODE plus typed params, never a prose sentence
|
|
504
|
+
* (ASSIST-PROGRESS-CONSOLIDATION A6). The producer reports what happened;
|
|
505
|
+
* each client renders it in the user's language — react-ui from its 29
|
|
506
|
+
* locales, the Go launcher from its English map. The vocabulary is frozen
|
|
507
|
+
* by the census of these call sites: adding a shape means adding a variant
|
|
508
|
+
* to `JobProgressMessage.json` and copy in every client, not composing a
|
|
509
|
+
* new sentence here.
|
|
510
|
+
*/
|
|
511
|
+
type OnProgress = (percentage: number, message: JobProgressMessage, extra?: Partial<JobProgress>) => void;
|
|
551
512
|
type JobProgress = components['schemas']['JobProgress'];
|
|
513
|
+
type JobProgressMessage = components['schemas']['JobProgressMessage'];
|
|
552
514
|
/** The five W3C motivations this system mints — a closed vocabulary, so it is
|
|
553
515
|
* typed as one rather than as `string`. */
|
|
554
516
|
type Motivation = Annotation['motivation'];
|
|
@@ -561,7 +523,7 @@ declare function processCommentJob(content: string, inferenceClient: InferenceCl
|
|
|
561
523
|
declare function processAssessmentJob(content: string, inferenceClient: InferenceClient, params: AssessmentDetectionParams, buildAnnotation: BuildAnnotation, onProgress: OnProgress): Promise<ProcessorResult<AssessmentDetectionResult>>;
|
|
562
524
|
declare function processReferenceJob(content: string, inferenceClient: InferenceClient, params: DetectionParams, buildAnnotation: BuildAnnotation, onProgress: OnProgress, logger: Logger): Promise<ProcessorResult<DetectionResult>>;
|
|
563
525
|
declare function processTagJob(content: string, inferenceClient: InferenceClient, params: TagDetectionParams, buildAnnotation: BuildAnnotation, onProgress: OnProgress): Promise<ProcessorResult<TagDetectionResult>>;
|
|
564
|
-
declare function processGenerationJob(inferenceClient: InferenceClient, params:
|
|
526
|
+
declare function processGenerationJob(inferenceClient: InferenceClient, params: GenerationJobParams, onProgress: OnProgress, logger: Logger): Promise<{
|
|
565
527
|
content: Uint8Array;
|
|
566
528
|
title: string;
|
|
567
529
|
format: SupportedMediaType;
|
|
@@ -645,7 +607,7 @@ declare class AnnotationDetection {
|
|
|
645
607
|
* (source-resource locale). See `types.ts` "Locale conventions" for the
|
|
646
608
|
* full discussion.
|
|
647
609
|
*/
|
|
648
|
-
static detectComments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string,
|
|
610
|
+
static detectComments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<CommentMatch[]>;
|
|
649
611
|
/**
|
|
650
612
|
* Detect highlights in content.
|
|
651
613
|
*
|
|
@@ -653,7 +615,7 @@ declare class AnnotationDetection {
|
|
|
653
615
|
* applies, used in the prompt so the LLM analyzes non-English source
|
|
654
616
|
* correctly.
|
|
655
617
|
*/
|
|
656
|
-
static detectHighlights(content: string, client: InferenceClient, instructions?: string, density?: number, sourceLanguage?: string,
|
|
618
|
+
static detectHighlights(content: string, client: InferenceClient, instructions?: string, density?: number, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<HighlightMatch[]>;
|
|
657
619
|
/**
|
|
658
620
|
* Detect assessments in content.
|
|
659
621
|
*
|
|
@@ -661,7 +623,7 @@ declare class AnnotationDetection {
|
|
|
661
623
|
* (annotation body locale). `sourceLanguage` is the locale of the content
|
|
662
624
|
* being analyzed (source-resource locale).
|
|
663
625
|
*/
|
|
664
|
-
static detectAssessments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string,
|
|
626
|
+
static detectAssessments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<AssessmentMatch[]>;
|
|
665
627
|
/**
|
|
666
628
|
* Detect tags in content for a specific category.
|
|
667
629
|
*
|
|
@@ -674,7 +636,7 @@ declare class AnnotationDetection {
|
|
|
674
636
|
* identifiers, not LLM-generated text — so it's consumed at the body-stamp
|
|
675
637
|
* site, not here.
|
|
676
638
|
*/
|
|
677
|
-
static detectTags(content: string, client: InferenceClient, schema: TagSchema, category: string, sourceLanguage?: string,
|
|
639
|
+
static detectTags(content: string, client: InferenceClient, schema: TagSchema, category: string, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<TagMatch[]>;
|
|
678
640
|
}
|
|
679
641
|
|
|
680
642
|
/**
|
|
@@ -700,6 +662,7 @@ declare function generateResourceFromTopic(topic: string, entityTypes: string[],
|
|
|
700
662
|
}): Promise<{
|
|
701
663
|
title: string;
|
|
702
664
|
content: string;
|
|
665
|
+
truncated: boolean;
|
|
703
666
|
}>;
|
|
704
667
|
|
|
705
668
|
/**
|
|
@@ -735,4 +698,4 @@ declare function generateResourceFromTopic(topic: string, entityTypes: string[],
|
|
|
735
698
|
declare const STALL_THRESHOLD_MS: number;
|
|
736
699
|
|
|
737
700
|
export { AnnotationDetection, FsJobQueue, STALL_THRESHOLD_MS, generateResourceFromTopic, isCancelledJob, isCompleteJob, isFailedJob, isPendingJob, isRunningJob, processAssessmentJob, processCommentJob, processGenerationJob, processHighlightJob, processReferenceJob, processTagJob };
|
|
738
|
-
export type { AnyJob, AssessmentDetectionJob, AssessmentDetectionParams, AssessmentDetectionProgress, AssessmentDetectionResult, CancelledJob, CommentDetectionJob, CommentDetectionParams, CommentDetectionProgress, CommentDetectionResult, CompleteJob, DetectionJob, DetectionParams, DetectionProgress, DetectionResult, FailedJob, GenerationJob,
|
|
701
|
+
export type { AnyJob, AssessmentDetectionJob, AssessmentDetectionParams, AssessmentDetectionProgress, AssessmentDetectionResult, CancelledJob, CommentDetectionJob, CommentDetectionParams, CommentDetectionProgress, CommentDetectionResult, CompleteJob, DetectionJob, DetectionParams, DetectionProgress, DetectionResult, FailedJob, GenerationJob, GenerationResult, HighlightDetectionJob, HighlightDetectionParams, HighlightDetectionProgress, HighlightDetectionResult, JobMetadata, JobQueryFilters, JobQueue, JobStatus, JobType, OnProgress, PendingJob, ProcessorResult, RunningJob, TagDetectionJob, TagDetectionParams, TagDetectionProgress, TagDetectionResult, YieldProgress };
|