@semiont/jobs 0.5.25 → 0.5.27
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 +27 -72
- package/dist/index.js +211 -147
- package/dist/index.js.map +1 -1
- package/dist/worker-main.js +246 -169
- package/dist/worker-main.js.map +1 -1
- package/package.json +8 -8
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
|
}
|
|
@@ -333,7 +275,7 @@ interface CancelledJob<P> {
|
|
|
333
275
|
*/
|
|
334
276
|
type Job<P, PG, R> = PendingJob<P> | RunningJob<P, PG> | CompleteJob<P, R> | FailedJob<P> | CancelledJob<P>;
|
|
335
277
|
type DetectionJob = Job<DetectionParams, DetectionProgress, DetectionResult>;
|
|
336
|
-
type GenerationJob = Job<
|
|
278
|
+
type GenerationJob = Job<GenerationJobParams, YieldProgress, GenerationResult>;
|
|
337
279
|
type HighlightDetectionJob = Job<HighlightDetectionParams, HighlightDetectionProgress, HighlightDetectionResult>;
|
|
338
280
|
type AssessmentDetectionJob = Job<AssessmentDetectionParams, AssessmentDetectionProgress, AssessmentDetectionResult>;
|
|
339
281
|
type CommentDetectionJob = Job<CommentDetectionParams, CommentDetectionProgress, CommentDetectionResult>;
|
|
@@ -541,14 +483,26 @@ type SpanMatch = {
|
|
|
541
483
|
*/
|
|
542
484
|
type BuildAnnotation = (motivation: Motivation, match: SpanMatch, body?: Annotation['body']) => Annotation;
|
|
543
485
|
/**
|
|
544
|
-
* Progress callback. The
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
* (`currentEntityType`, `completedEntityTypes`, `requestParams`, etc.)
|
|
486
|
+
* Progress callback. The two positional args are the required `JobProgress`
|
|
487
|
+
* fields (`percentage`, `message`). The third optional arg carries the
|
|
488
|
+
* job-type-specific fields (`completedEntityTypes`, `requestParams`, etc.)
|
|
548
489
|
* that the progress UI renders.
|
|
549
|
-
|
|
550
|
-
|
|
490
|
+
*
|
|
491
|
+
* Anything in `extra` describing the RUN rather than the moment must be passed
|
|
492
|
+
* on EVERY call: the client's `progress$` replaces its value per event, so a
|
|
493
|
+
* field sent once disappears on the next tick.
|
|
494
|
+
*
|
|
495
|
+
* `message` is a CODE plus typed params, never a prose sentence
|
|
496
|
+
* (ASSIST-PROGRESS-CONSOLIDATION A6). The producer reports what happened;
|
|
497
|
+
* each client renders it in the user's language — react-ui from its 29
|
|
498
|
+
* locales, the Go launcher from its English map. The vocabulary is frozen
|
|
499
|
+
* by the census of these call sites: adding a shape means adding a variant
|
|
500
|
+
* to `JobProgressMessage.json` and copy in every client, not composing a
|
|
501
|
+
* new sentence here.
|
|
502
|
+
*/
|
|
503
|
+
type OnProgress = (percentage: number, message: JobProgressMessage, extra?: Partial<JobProgress>) => void;
|
|
551
504
|
type JobProgress = components['schemas']['JobProgress'];
|
|
505
|
+
type JobProgressMessage = components['schemas']['JobProgressMessage'];
|
|
552
506
|
/** The five W3C motivations this system mints — a closed vocabulary, so it is
|
|
553
507
|
* typed as one rather than as `string`. */
|
|
554
508
|
type Motivation = Annotation['motivation'];
|
|
@@ -561,7 +515,7 @@ declare function processCommentJob(content: string, inferenceClient: InferenceCl
|
|
|
561
515
|
declare function processAssessmentJob(content: string, inferenceClient: InferenceClient, params: AssessmentDetectionParams, buildAnnotation: BuildAnnotation, onProgress: OnProgress): Promise<ProcessorResult<AssessmentDetectionResult>>;
|
|
562
516
|
declare function processReferenceJob(content: string, inferenceClient: InferenceClient, params: DetectionParams, buildAnnotation: BuildAnnotation, onProgress: OnProgress, logger: Logger): Promise<ProcessorResult<DetectionResult>>;
|
|
563
517
|
declare function processTagJob(content: string, inferenceClient: InferenceClient, params: TagDetectionParams, buildAnnotation: BuildAnnotation, onProgress: OnProgress): Promise<ProcessorResult<TagDetectionResult>>;
|
|
564
|
-
declare function processGenerationJob(inferenceClient: InferenceClient, params:
|
|
518
|
+
declare function processGenerationJob(inferenceClient: InferenceClient, params: GenerationJobParams, onProgress: OnProgress, logger: Logger): Promise<{
|
|
565
519
|
content: Uint8Array;
|
|
566
520
|
title: string;
|
|
567
521
|
format: SupportedMediaType;
|
|
@@ -579,6 +533,7 @@ declare function processGenerationJob(inferenceClient: InferenceClient, params:
|
|
|
579
533
|
* NOTE: These are static utility methods without logger access.
|
|
580
534
|
* Console statements kept for debugging - consider adding logger parameter in future.
|
|
581
535
|
*/
|
|
536
|
+
|
|
582
537
|
/**
|
|
583
538
|
* Represents a detected comment with validated position
|
|
584
539
|
*/
|
|
@@ -644,7 +599,7 @@ declare class AnnotationDetection {
|
|
|
644
599
|
* (source-resource locale). See `types.ts` "Locale conventions" for the
|
|
645
600
|
* full discussion.
|
|
646
601
|
*/
|
|
647
|
-
static detectComments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string,
|
|
602
|
+
static detectComments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<CommentMatch[]>;
|
|
648
603
|
/**
|
|
649
604
|
* Detect highlights in content.
|
|
650
605
|
*
|
|
@@ -652,7 +607,7 @@ declare class AnnotationDetection {
|
|
|
652
607
|
* applies, used in the prompt so the LLM analyzes non-English source
|
|
653
608
|
* correctly.
|
|
654
609
|
*/
|
|
655
|
-
static detectHighlights(content: string, client: InferenceClient, instructions?: string, density?: number, sourceLanguage?: string,
|
|
610
|
+
static detectHighlights(content: string, client: InferenceClient, instructions?: string, density?: number, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<HighlightMatch[]>;
|
|
656
611
|
/**
|
|
657
612
|
* Detect assessments in content.
|
|
658
613
|
*
|
|
@@ -660,7 +615,7 @@ declare class AnnotationDetection {
|
|
|
660
615
|
* (annotation body locale). `sourceLanguage` is the locale of the content
|
|
661
616
|
* being analyzed (source-resource locale).
|
|
662
617
|
*/
|
|
663
|
-
static detectAssessments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string,
|
|
618
|
+
static detectAssessments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<AssessmentMatch[]>;
|
|
664
619
|
/**
|
|
665
620
|
* Detect tags in content for a specific category.
|
|
666
621
|
*
|
|
@@ -673,7 +628,7 @@ declare class AnnotationDetection {
|
|
|
673
628
|
* identifiers, not LLM-generated text — so it's consumed at the body-stamp
|
|
674
629
|
* site, not here.
|
|
675
630
|
*/
|
|
676
|
-
static detectTags(content: string, client: InferenceClient, schema: TagSchema, category: string, sourceLanguage?: string,
|
|
631
|
+
static detectTags(content: string, client: InferenceClient, schema: TagSchema, category: string, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<TagMatch[]>;
|
|
677
632
|
}
|
|
678
633
|
|
|
679
634
|
/**
|
|
@@ -734,4 +689,4 @@ declare function generateResourceFromTopic(topic: string, entityTypes: string[],
|
|
|
734
689
|
declare const STALL_THRESHOLD_MS: number;
|
|
735
690
|
|
|
736
691
|
export { AnnotationDetection, FsJobQueue, STALL_THRESHOLD_MS, generateResourceFromTopic, isCancelledJob, isCompleteJob, isFailedJob, isPendingJob, isRunningJob, processAssessmentJob, processCommentJob, processGenerationJob, processHighlightJob, processReferenceJob, processTagJob };
|
|
737
|
-
export type { AnyJob, AssessmentDetectionJob, AssessmentDetectionParams, AssessmentDetectionProgress, AssessmentDetectionResult, CancelledJob, CommentDetectionJob, CommentDetectionParams, CommentDetectionProgress, CommentDetectionResult, CompleteJob, DetectionJob, DetectionParams, DetectionProgress, DetectionResult, FailedJob, GenerationJob,
|
|
692
|
+
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 };
|