@semiont/jobs 0.5.26 → 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 CHANGED
@@ -30,8 +30,8 @@ npm install @semiont/jobs
30
30
  ## Quick Start
31
31
 
32
32
  ```typescript
33
- import { FsJobQueue, type PendingJob, type GenerationParams } from '@semiont/jobs';
34
- import { EventBus, userId, resourceId, annotationId, jobId } from '@semiont/core';
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<GenerationParams> = {
44
+ const job: PendingJob<DetectionParams> = {
45
45
  status: 'pending',
46
46
  metadata: {
47
47
  id: jobId('job-abc123'),
48
- type: 'generation',
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: 3,
55
+ maxRetries: 1,
56
56
  },
57
57
  params: {
58
- referenceId: annotationId('ref-123'),
59
- sourceResourceId: resourceId('doc-456'),
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, AnnotationId, GatheredContext, SupportedMediaType, TagSchema, Logger, EventBus, components, Annotation } from '@semiont/core';
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<GenerationParams, YieldProgress, GenerationResult>;
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 three positional args satisfy the minimum
545
- * `JobProgress` required fields (`percentage`, `message`, `stage`).
546
- * The fourth optional arg carries job-type-specific fields
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
- type OnProgress = (percentage: number, message: string, stage: string, extra?: Partial<JobProgress>) => void;
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: GenerationParams, onProgress: OnProgress, logger: Logger): Promise<{
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;
@@ -645,7 +599,7 @@ declare class AnnotationDetection {
645
599
  * (source-resource locale). See `types.ts` "Locale conventions" for the
646
600
  * full discussion.
647
601
  */
648
- static detectComments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string, onChunk?: (completedChunks: number, totalChunks: number) => void): Promise<CommentMatch[]>;
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[]>;
649
603
  /**
650
604
  * Detect highlights in content.
651
605
  *
@@ -653,7 +607,7 @@ declare class AnnotationDetection {
653
607
  * applies, used in the prompt so the LLM analyzes non-English source
654
608
  * correctly.
655
609
  */
656
- static detectHighlights(content: string, client: InferenceClient, instructions?: string, density?: number, sourceLanguage?: string, onChunk?: (completedChunks: number, totalChunks: number) => void): Promise<HighlightMatch[]>;
610
+ static detectHighlights(content: string, client: InferenceClient, instructions?: string, density?: number, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<HighlightMatch[]>;
657
611
  /**
658
612
  * Detect assessments in content.
659
613
  *
@@ -661,7 +615,7 @@ declare class AnnotationDetection {
661
615
  * (annotation body locale). `sourceLanguage` is the locale of the content
662
616
  * being analyzed (source-resource locale).
663
617
  */
664
- static detectAssessments(content: string, client: InferenceClient, instructions?: string, tone?: string, density?: number, language?: string, sourceLanguage?: string, onChunk?: (completedChunks: number, totalChunks: number) => void): Promise<AssessmentMatch[]>;
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[]>;
665
619
  /**
666
620
  * Detect tags in content for a specific category.
667
621
  *
@@ -674,7 +628,7 @@ declare class AnnotationDetection {
674
628
  * identifiers, not LLM-generated text — so it's consumed at the body-stamp
675
629
  * site, not here.
676
630
  */
677
- static detectTags(content: string, client: InferenceClient, schema: TagSchema, category: string, sourceLanguage?: string, onChunk?: (completedChunks: number, totalChunks: number) => void): Promise<TagMatch[]>;
631
+ static detectTags(content: string, client: InferenceClient, schema: TagSchema, category: string, sourceLanguage?: string, onActivity?: (completedChunks: number, totalChunks: number) => void): Promise<TagMatch[]>;
678
632
  }
679
633
 
680
634
  /**
@@ -735,4 +689,4 @@ declare function generateResourceFromTopic(topic: string, entityTypes: string[],
735
689
  declare const STALL_THRESHOLD_MS: number;
736
690
 
737
691
  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, GenerationParams, GenerationResult, HighlightDetectionJob, HighlightDetectionParams, HighlightDetectionProgress, HighlightDetectionResult, JobMetadata, JobQueryFilters, JobQueue, JobStatus, JobType, OnProgress, PendingJob, ProcessorResult, RunningJob, TagDetectionJob, TagDetectionParams, TagDetectionProgress, TagDetectionResult, YieldProgress };
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 };