@ftai/dsh-plugin-acn 0.0.0-stage → 0.1.0
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/CHANGELOG.md +79 -0
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +19 -0
- package/README.md +55 -2
- package/README_EN.md +56 -0
- package/cordis.patch.yml +29 -0
- package/docs/acn-compat.md +33 -0
- package/docs/architecture.md +129 -0
- package/docs/assets/activity-view.png +0 -0
- package/docs/assets/install-package.png +0 -0
- package/docs/assets/knowledge-model.png +0 -0
- package/docs/assets/knowledge-view.png +0 -0
- package/docs/assets/personal-configuration.png +0 -0
- package/docs/assets/session-upstream.png +0 -0
- package/docs/assets/upstream-settings.png +0 -0
- package/docs/assets/upstream-team.png +0 -0
- package/docs/command-reference.md +201 -0
- package/docs/config.md +243 -0
- package/docs/development.md +197 -0
- package/docs/dsh-compat.md +59 -0
- package/docs/index.md +16 -0
- package/docs/outstanding-issues.md +61 -0
- package/docs/user_guide.md +183 -0
- package/icon.svg +8 -0
- package/lib/activities-LRoCwpzw.js +327 -0
- package/lib/alignment-CwH0nBf-.js +80 -0
- package/lib/auth-DFI9yowX.js +71 -0
- package/lib/checkpoint-Bmt8q2vB.js +188 -0
- package/lib/checkpoint-RgcdqifN.js +318 -0
- package/lib/claim-DOAGe8ZK.js +168 -0
- package/lib/client.js +18420 -0
- package/lib/deliver-BuYQaPRW.js +168 -0
- package/lib/delivery-status-D5m3178s.js +87 -0
- package/lib/dispute-CtrInHzf.js +20 -0
- package/lib/disputes-ByEmi43j.js +51 -0
- package/lib/dream-agent-DBszTHXY.js +249 -0
- package/lib/dream.js +4 -0
- package/lib/effects-DJ4Xa7Tx.js +268 -0
- package/lib/errors-Bp_2WXBr.js +19 -0
- package/lib/errors-pPumDOGD.js +18 -0
- package/lib/evidence-store-DLFvSuNa.js +1030 -0
- package/lib/formation-D4LO31WW.js +187 -0
- package/lib/formation-replay-CEOy5FkI.js +87 -0
- package/lib/formation.js +9 -0
- package/lib/inbox-2CugZZQm.js +188 -0
- package/lib/inbox-DFtE2fOp.js +71 -0
- package/lib/inbox.js +3 -0
- package/lib/index.js +1377 -0
- package/lib/lock-DbmlKOoX.js +332 -0
- package/lib/pages-BEWC3kmZ.js +51 -0
- package/lib/paths-CDYV5UH9.js +154 -0
- package/lib/plugins/commands.js +590 -0
- package/lib/plugins/dream.js +66 -0
- package/lib/plugins/formation.js +66 -0
- package/lib/plugins/inbox.js +53 -0
- package/lib/plugins/knowledge.js +1111 -0
- package/lib/plugins/prompt.js +102 -0
- package/lib/plugins/tools.js +280 -0
- package/lib/policy-DnyHh7Bl.js +16 -0
- package/lib/prepare-DwHZudbA.js +134 -0
- package/lib/presentation-BlLjgDjP.js +47 -0
- package/lib/protocol.js +8 -0
- package/lib/queue-M917xHPS.js +153 -0
- package/lib/regular-file-BFpqMoub.js +136 -0
- package/lib/render-CJaVcKKC.js +48 -0
- package/lib/reported-sets-DdEKdeVb.js +122 -0
- package/lib/revision-DeoL_IUN.js +11 -0
- package/lib/scheduler-MaUEbXr3.js +64 -0
- package/lib/service-B7AI5jds.js +344 -0
- package/lib/service-BcHV5mc7.js +305 -0
- package/lib/service-CNjqHCBR.js +505 -0
- package/lib/service-C_i3BzdP.js +1106 -0
- package/lib/session-binding-BQrOGhZI.js +151 -0
- package/lib/session-state-CYqUhC95.js +38 -0
- package/lib/sessions-C2xuPFQv.js +218 -0
- package/lib/store.js +16 -0
- package/lib/structured-lyQCK-Zk.js +452 -0
- package/lib/subagent-yJsFxHmH.js +9 -0
- package/lib/team-credentials-C9xHrPIi.js +579 -0
- package/lib/team.js +3 -0
- package/lib/tool-schema-3b4gH1zf.js +28 -0
- package/lib/trace-Da0RnL5R.js +14 -0
- package/lib/traces-CHBo8y1z.js +11 -0
- package/lib/types/activities.d.ts +71 -0
- package/lib/types/advanced-configuration.d.ts +11 -0
- package/lib/types/client/ActivityDetails.d.ts +18 -0
- package/lib/types/client/AdvancedPreferences.d.ts +8 -0
- package/lib/types/client/BlankCommandFeedback.d.ts +10 -0
- package/lib/types/client/ComposerMenu.d.ts +24 -0
- package/lib/types/client/ConfigurationPage.d.ts +11 -0
- package/lib/types/client/ConnectionCheckDialog.d.ts +12 -0
- package/lib/types/client/KnowledgeDetail.d.ts +6 -0
- package/lib/types/client/KnowledgeDirectoryField.d.ts +11 -0
- package/lib/types/client/KnowledgePanel.d.ts +12 -0
- package/lib/types/client/KnowledgeReference.d.ts +13 -0
- package/lib/types/client/SessionToolbar.d.ts +16 -0
- package/lib/types/client/SettingsToast.d.ts +3 -0
- package/lib/types/client/SourceSessionLink.d.ts +15 -0
- package/lib/types/client/TeamCredentialField.d.ts +16 -0
- package/lib/types/client/TeamSettingsPage.d.ts +30 -0
- package/lib/types/client/configuration-errors.d.ts +2 -0
- package/lib/types/client/interaction-styles.d.ts +1 -0
- package/lib/types/client/interaction-ui.d.ts +30 -0
- package/lib/types/client/knowledge-labels.d.ts +5 -0
- package/lib/types/client/locales.d.ts +51 -0
- package/lib/types/commands/claim.d.ts +4 -0
- package/lib/types/commands/import.d.ts +10 -0
- package/lib/types/commands/status.d.ts +5 -0
- package/lib/types/config.d.ts +122 -0
- package/lib/types/configuration.d.ts +259 -0
- package/lib/types/credentials.d.ts +65 -0
- package/lib/types/dream/audit.d.ts +4 -0
- package/lib/types/dream/autonomous.d.ts +185 -0
- package/lib/types/dream/candidates.d.ts +34 -0
- package/lib/types/dream/checkpoint.d.ts +35 -0
- package/lib/types/dream/evidence-files.d.ts +10 -0
- package/lib/types/dream/evidence-store.d.ts +103 -0
- package/lib/types/dream/evidence.d.ts +30 -0
- package/lib/types/dream/index.d.ts +10 -0
- package/lib/types/dream/plan.d.ts +18 -0
- package/lib/types/dream/preservation.d.ts +6 -0
- package/lib/types/dream/review.d.ts +10 -0
- package/lib/types/dream/schema.d.ts +1475 -0
- package/lib/types/dream/service.d.ts +56 -0
- package/lib/types/dream/sync.d.ts +147 -0
- package/lib/types/dsh-adapter/configuration-remote.d.ts +1 -0
- package/lib/types/dsh-adapter/configuration-service.d.ts +28 -0
- package/lib/types/dsh-adapter/dream-agent.d.ts +4 -0
- package/lib/types/dsh-adapter/dream-evidence.d.ts +3 -0
- package/lib/types/dsh-adapter/formation-archive.d.ts +3 -0
- package/lib/types/dsh-adapter/formation-replay.d.ts +5 -0
- package/lib/types/dsh-adapter/formation.d.ts +4 -0
- package/lib/types/dsh-adapter/interaction-service.d.ts +13 -0
- package/lib/types/dsh-adapter/knowledge-paths.d.ts +3 -0
- package/lib/types/dsh-adapter/llm.d.ts +10 -0
- package/lib/types/dsh-adapter/project-upstream.d.ts +4 -0
- package/lib/types/dsh-adapter/runtime-pool.d.ts +110 -0
- package/lib/types/dsh-adapter/session-binding.d.ts +43 -0
- package/lib/types/dsh-adapter/source-sessions.d.ts +3 -0
- package/lib/types/dsh-adapter/team-credentials.d.ts +5 -0
- package/lib/types/dsh-adapter/tool-schema.d.ts +4 -0
- package/lib/types/dsh-adapter/tools.d.ts +5 -0
- package/lib/types/formation/capture.d.ts +19 -0
- package/lib/types/formation/checkpoint.d.ts +136 -0
- package/lib/types/formation/index.d.ts +10 -0
- package/lib/types/formation/prepare.d.ts +16 -0
- package/lib/types/formation/schema.d.ts +45 -0
- package/lib/types/formation/service.d.ts +58 -0
- package/lib/types/formation/transcript.d.ts +75 -0
- package/lib/types/formation/triggers.d.ts +3 -0
- package/lib/types/inbox/cascade.d.ts +3 -0
- package/lib/types/inbox/effects.d.ts +275 -0
- package/lib/types/inbox/index.d.ts +5 -0
- package/lib/types/inbox/prepare.d.ts +380 -0
- package/lib/types/inbox/service.d.ts +26 -0
- package/lib/types/inbox/sync.d.ts +9 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/interaction-messages.d.ts +69 -0
- package/lib/types/interaction.d.ts +550 -0
- package/lib/types/knowledge/alignment.d.ts +49 -0
- package/lib/types/knowledge/catalog.d.ts +5 -0
- package/lib/types/knowledge/changes.d.ts +32 -0
- package/lib/types/knowledge/disputes.d.ts +3 -0
- package/lib/types/knowledge/errors.d.ts +9 -0
- package/lib/types/knowledge/ordering.d.ts +7 -0
- package/lib/types/knowledge/pages.d.ts +7 -0
- package/lib/types/knowledge/safety.d.ts +2 -0
- package/lib/types/knowledge/service.d.ts +52 -0
- package/lib/types/knowledge/sessions.d.ts +59 -0
- package/lib/types/knowledge/sources.d.ts +2 -0
- package/lib/types/knowledge/timestamps.d.ts +1 -0
- package/lib/types/knowledge/types.d.ts +84 -0
- package/lib/types/llm/response.d.ts +1 -0
- package/lib/types/llm/structured.d.ts +27 -0
- package/lib/types/local-name.d.ts +1 -0
- package/lib/types/plugins/client.d.ts +9 -0
- package/lib/types/plugins/commands.d.ts +11 -0
- package/lib/types/plugins/configuration.d.ts +8 -0
- package/lib/types/plugins/dream.d.ts +16 -0
- package/lib/types/plugins/formation.d.ts +16 -0
- package/lib/types/plugins/inbox.d.ts +16 -0
- package/lib/types/plugins/knowledge.d.ts +19 -0
- package/lib/types/plugins/prompt.d.ts +17 -0
- package/lib/types/plugins/tools.d.ts +10 -0
- package/lib/types/prompt/render.d.ts +2 -0
- package/lib/types/protocol/arbitration.d.ts +154 -0
- package/lib/types/protocol/auth.d.ts +31 -0
- package/lib/types/protocol/claim.d.ts +36 -0
- package/lib/types/protocol/dispute.d.ts +17 -0
- package/lib/types/protocol/ids.d.ts +20 -0
- package/lib/types/protocol/inbox.d.ts +141 -0
- package/lib/types/protocol/index.d.ts +11 -0
- package/lib/types/protocol/policy.d.ts +21 -0
- package/lib/types/protocol/revision.d.ts +2 -0
- package/lib/types/protocol/router.d.ts +114 -0
- package/lib/types/protocol/schema.d.ts +4 -0
- package/lib/types/protocol/time.d.ts +5 -0
- package/lib/types/protocol/trace.d.ts +11 -0
- package/lib/types/store/atomic.d.ts +8 -0
- package/lib/types/store/claim-edits.d.ts +33 -0
- package/lib/types/store/claims.d.ts +7 -0
- package/lib/types/store/context.d.ts +13 -0
- package/lib/types/store/delivery-status.d.ts +47 -0
- package/lib/types/store/disputes.d.ts +6 -0
- package/lib/types/store/entities.d.ts +16 -0
- package/lib/types/store/errors.d.ts +8 -0
- package/lib/types/store/inbox.d.ts +27 -0
- package/lib/types/store/index.d.ts +16 -0
- package/lib/types/store/jobs.d.ts +5 -0
- package/lib/types/store/lock.d.ts +11 -0
- package/lib/types/store/path-names.d.ts +2 -0
- package/lib/types/store/paths.d.ts +45 -0
- package/lib/types/store/presentation.d.ts +13 -0
- package/lib/types/store/regular-file.d.ts +2 -0
- package/lib/types/store/rejected-disputes.d.ts +18 -0
- package/lib/types/store/rename.d.ts +1 -0
- package/lib/types/store/reported-sets.d.ts +24 -0
- package/lib/types/store/session-state.d.ts +17 -0
- package/lib/types/store/traces.d.ts +6 -0
- package/lib/types/store/uploads.d.ts +312 -0
- package/lib/types/store/yaml.d.ts +8 -0
- package/lib/types/team/errors.d.ts +10 -0
- package/lib/types/team/http.d.ts +20 -0
- package/lib/types/team/index.d.ts +5 -0
- package/lib/types/team/maintainer-client.d.ts +18 -0
- package/lib/types/team/router-client.d.ts +14 -0
- package/lib/types/team/service.d.ts +28 -0
- package/lib/types/team/system-proxy.d.ts +9 -0
- package/lib/types/tools/claim.d.ts +63 -0
- package/lib/types/tools/consult-router.d.ts +11 -0
- package/lib/types/tools/subagent.d.ts +8 -0
- package/lib/types/tools/validation.d.ts +2 -0
- package/lib/types/upload/consolidation.d.ts +63 -0
- package/lib/types/upload/deliver.d.ts +15 -0
- package/lib/types/upload/index.d.ts +2 -0
- package/lib/types/upload/scheduler.d.ts +19 -0
- package/lib/types/upstreams.d.ts +5 -0
- package/lib/types/worker/queue.d.ts +17 -0
- package/lib/types/worker/types.d.ts +51 -0
- package/lib/types/worker/worker.d.ts +39 -0
- package/lib/types-C2ST2Zdg.js +17 -0
- package/lib/upload.js +3 -0
- package/lib/uploads-BCA2p92b.js +210 -0
- package/lib/worker-BBTYP2RE.js +185 -0
- package/locale/commands/en.json +1 -0
- package/locale/commands/zh.json +1 -0
- package/locale/dream/en.json +1 -0
- package/locale/dream/zh.json +1 -0
- package/locale/en.json +7 -0
- package/locale/formation/en.json +1 -0
- package/locale/formation/zh.json +1 -0
- package/locale/inbox/en.json +1 -0
- package/locale/inbox/zh.json +1 -0
- package/locale/knowledge/en.json +1 -0
- package/locale/knowledge/zh.json +1 -0
- package/locale/prompt/en.json +1 -0
- package/locale/prompt/zh.json +1 -0
- package/locale/tools/en.json +1 -0
- package/locale/tools/zh.json +1 -0
- package/locale/zh.json +7 -0
- package/package.json +262 -3
- package/prompts/claim_dream.j2 +77 -0
- package/prompts/claim_dream_legacy.j2 +63 -0
- package/prompts/dream_compaction.j2 +11 -0
- package/prompts/dream_evidence.j2 +5 -0
- package/prompts/inbox_claim_attribute_update_internalize.j2 +112 -0
- package/prompts/inbox_policy_update_internalize.j2 +87 -0
- package/prompts/knowledge.j2 +38 -0
- package/prompts/session_recap.j2 +113 -0
- package/prompts/what_is_claim.j2 +51 -0
- package/prompts/what_is_dispute.j2 +21 -0
- package/prompts/what_is_policy.j2 +22 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StoreContext } from '../store/context.js';
|
|
2
|
+
import type { TeamFacade } from '../team/service.js';
|
|
3
|
+
export interface DeliveryReport {
|
|
4
|
+
deliveredClaims: number;
|
|
5
|
+
deliveredDisputes: number;
|
|
6
|
+
pendingClaims: number;
|
|
7
|
+
pendingDisputes: number;
|
|
8
|
+
warnings: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare class UploadDelivery {
|
|
11
|
+
readonly context: StoreContext;
|
|
12
|
+
readonly team: TeamFacade | null;
|
|
13
|
+
constructor(context: StoreContext, team: TeamFacade | null);
|
|
14
|
+
deliver(signal?: AbortSignal): Promise<DeliveryReport>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AcnKnowledge } from '../knowledge/service.js';
|
|
2
|
+
import { UploadDelivery } from './deliver.js';
|
|
3
|
+
export declare class UploadScheduler {
|
|
4
|
+
readonly knowledge: AcnKnowledge;
|
|
5
|
+
private readonly intervalMs;
|
|
6
|
+
private pending;
|
|
7
|
+
private requested;
|
|
8
|
+
private closed;
|
|
9
|
+
private readonly abort;
|
|
10
|
+
private timer;
|
|
11
|
+
private unsubscribe;
|
|
12
|
+
readonly delivery: UploadDelivery;
|
|
13
|
+
constructor(knowledge: AcnKnowledge, intervalMs?: number);
|
|
14
|
+
start(): void;
|
|
15
|
+
kick(): void;
|
|
16
|
+
private run;
|
|
17
|
+
flush(): Promise<void>;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ResolvedConfig } from './config.js';
|
|
2
|
+
export { upstreamsOf } from './config.js';
|
|
3
|
+
export declare function resolveUpstream(config: ResolvedConfig, key: string, includeDisabled?: boolean): ResolvedConfig | undefined;
|
|
4
|
+
export declare function defaultUpstream(config: ResolvedConfig): string;
|
|
5
|
+
export declare function canonicalProjectPath(cwd: string): Promise<string>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { StoreContext } from '../store/context.js';
|
|
2
|
+
import type { Job, JobKind } from './types.js';
|
|
3
|
+
export declare function runnableJob(job: Job, kinds: Pick<ReadonlySet<JobKind>, 'has'>, now?: number): boolean;
|
|
4
|
+
export declare class JobQueue {
|
|
5
|
+
readonly context: StoreContext;
|
|
6
|
+
constructor(context: StoreContext);
|
|
7
|
+
list(): Promise<Job[]>;
|
|
8
|
+
read(id: string): Promise<Job | null>;
|
|
9
|
+
private write;
|
|
10
|
+
private locked;
|
|
11
|
+
enqueue(kind: JobKind, payload: Job['payload'], sessionId?: string): Promise<Job>;
|
|
12
|
+
recoverRunning(): Promise<void>;
|
|
13
|
+
claim(kinds: ReadonlySet<JobKind>): Promise<Job | null>;
|
|
14
|
+
settle(job: Job, state: Job['state'], details?: Partial<Pick<Job, 'lastError' | 'lastErrorKind' | 'nextRunAt' | 'result' | 'attempts'>>): Promise<void>;
|
|
15
|
+
pauseDream(paused: boolean): Promise<Job[]>;
|
|
16
|
+
retry(id: string): Promise<Job>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const JobKindSchema: z.ZodEnum<{
|
|
3
|
+
inbox: "inbox";
|
|
4
|
+
dream: "dream";
|
|
5
|
+
finalize: "finalize";
|
|
6
|
+
recap: "recap";
|
|
7
|
+
}>;
|
|
8
|
+
export type JobKind = z.infer<typeof JobKindSchema>;
|
|
9
|
+
export declare const JobSchema: z.ZodObject<{
|
|
10
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
kind: z.ZodEnum<{
|
|
13
|
+
inbox: "inbox";
|
|
14
|
+
dream: "dream";
|
|
15
|
+
finalize: "finalize";
|
|
16
|
+
recap: "recap";
|
|
17
|
+
}>;
|
|
18
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
19
|
+
payload: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
20
|
+
state: z.ZodEnum<{
|
|
21
|
+
queued: "queued";
|
|
22
|
+
running: "running";
|
|
23
|
+
succeeded: "succeeded";
|
|
24
|
+
failed: "failed";
|
|
25
|
+
}>;
|
|
26
|
+
attempts: z.ZodNumber;
|
|
27
|
+
createdAt: z.ZodNumber;
|
|
28
|
+
updatedAt: z.ZodNumber;
|
|
29
|
+
ordinal: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
nextRunAt: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
lastError: z.ZodOptional<z.ZodString>;
|
|
32
|
+
lastErrorKind: z.ZodOptional<z.ZodString>;
|
|
33
|
+
result: z.ZodOptional<z.ZodJSONSchema>;
|
|
34
|
+
}, z.core.$strict>;
|
|
35
|
+
export type Job = z.infer<typeof JobSchema>;
|
|
36
|
+
export declare const jobPriority: Record<JobKind, number>;
|
|
37
|
+
export declare class JobError extends Error {
|
|
38
|
+
readonly kind: string;
|
|
39
|
+
readonly retryable: boolean;
|
|
40
|
+
readonly retryAfterMs?: number | undefined;
|
|
41
|
+
constructor(kind: string, message: string, retryable?: boolean, retryAfterMs?: number | undefined);
|
|
42
|
+
}
|
|
43
|
+
export declare class Preempted extends JobError {
|
|
44
|
+
constructor();
|
|
45
|
+
}
|
|
46
|
+
export declare class DreamStopped extends JobError {
|
|
47
|
+
constructor();
|
|
48
|
+
}
|
|
49
|
+
export declare class DreamYield extends JobError {
|
|
50
|
+
constructor();
|
|
51
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { StoreContext } from '../store/context.js';
|
|
2
|
+
import { JobQueue } from './queue.js';
|
|
3
|
+
import { DreamStopped } from './types.js';
|
|
4
|
+
import type { Job, JobKind } from './types.js';
|
|
5
|
+
export interface JobControl {
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
prepared(): void;
|
|
8
|
+
committed?(): void;
|
|
9
|
+
}
|
|
10
|
+
export type JobHandler = (job: Job, control: JobControl) => Promise<Job['result']>;
|
|
11
|
+
export declare class DurableWorker {
|
|
12
|
+
readonly context: StoreContext;
|
|
13
|
+
private readonly options;
|
|
14
|
+
readonly queue: JobQueue;
|
|
15
|
+
private readonly handlers;
|
|
16
|
+
private lease;
|
|
17
|
+
private active;
|
|
18
|
+
private timer;
|
|
19
|
+
private ticking;
|
|
20
|
+
private closed;
|
|
21
|
+
private started;
|
|
22
|
+
private nextAcquire;
|
|
23
|
+
constructor(context: StoreContext, options?: {
|
|
24
|
+
pollMs?: number;
|
|
25
|
+
takeoverMs?: number;
|
|
26
|
+
retryBaseMs?: number;
|
|
27
|
+
staleMs?: number;
|
|
28
|
+
});
|
|
29
|
+
register(kind: JobKind, handler: JobHandler): () => void;
|
|
30
|
+
supports(kind: JobKind): boolean;
|
|
31
|
+
canRun(job: Job): boolean;
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
wake(force?: boolean): void;
|
|
34
|
+
enqueue(kind: JobKind, payload: Job['payload'], sessionId?: string): Promise<Job>;
|
|
35
|
+
retry(id: string): Promise<Job>;
|
|
36
|
+
cancelDream(reason?: DreamStopped): void;
|
|
37
|
+
private tick;
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { a as TextSchema, l as ClaimIdSchema, n as ClaimStatusSchema, r as ConfidenceSchema } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/knowledge/types.ts
|
|
4
|
+
const DEFAULT_TRACE_TASK_PAGE_LIMIT = 4e3;
|
|
5
|
+
const MAX_TRACE_TASK_PAGE_LIMIT = 16e3;
|
|
6
|
+
const ClaimUpdateSchema = z.strictObject({
|
|
7
|
+
id: ClaimIdSchema,
|
|
8
|
+
expected_revision: z.string(),
|
|
9
|
+
name: TextSchema.optional(),
|
|
10
|
+
statement: TextSchema.optional(),
|
|
11
|
+
scope: TextSchema.optional(),
|
|
12
|
+
evidence_summary: TextSchema.optional(),
|
|
13
|
+
confidence: ConfidenceSchema.optional(),
|
|
14
|
+
status: ClaimStatusSchema.optional()
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { DEFAULT_TRACE_TASK_PAGE_LIMIT as n, MAX_TRACE_TASK_PAGE_LIMIT as r, ClaimUpdateSchema as t };
|
package/lib/upload.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { S as timestampNanos, i as effectiveUpdatedAt, l as ClaimIdSchema, t as ClaimSchema, u as DisputeIdSchema, x as nowSeconds, y as TimestampSchema } from "./claim-DOAGe8ZK.js";
|
|
2
|
+
import { n as claimRevision } from "./revision-DeoL_IUN.js";
|
|
3
|
+
import { C as StoreError, c as readYamlOr, d as removeFile, l as writeYamlAtomic, n as withFileLock } from "./lock-DbmlKOoX.js";
|
|
4
|
+
import { l as sameClaim } from "./alignment-CwH0nBf-.js";
|
|
5
|
+
import { t as DisputeSchema } from "./dispute-CtrInHzf.js";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
//#region src/upload/consolidation.ts
|
|
9
|
+
function relatedIds(groups) {
|
|
10
|
+
return new Set(groups.flatMap((group) => [group.retired.id, ...group.carriers.map((claim) => claim.id)]));
|
|
11
|
+
}
|
|
12
|
+
function carrierReady(claim, groups, acknowledged, current, visiting) {
|
|
13
|
+
if (claim.status !== "deprecated" && current.some((value) => sameClaim(value, claim)) && acknowledged.some((value) => sameClaim(value, claim))) return true;
|
|
14
|
+
if (visiting.has(claim.id)) return false;
|
|
15
|
+
visiting.add(claim.id);
|
|
16
|
+
const result = groups.some((group) => sameClaim(group.before, claim) && current.some((value) => sameClaim(value, group.retired)) && group.carriers.length > 0 && group.carriers.every((carrier) => carrierReady(carrier, groups, acknowledged, current, visiting)));
|
|
17
|
+
visiting.delete(claim.id);
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
function consolidationReady(claim, groups, acknowledged, current) {
|
|
21
|
+
return groups.filter((group) => sameClaim(group.retired, claim)).every((group) => group.carriers.length > 0 && group.carriers.every((carrier) => carrierReady(carrier, groups, acknowledged, current, /* @__PURE__ */ new Set())));
|
|
22
|
+
}
|
|
23
|
+
function pruneDeliveries(groups, acknowledgements, pending) {
|
|
24
|
+
const keep = new Set(groups.filter((group) => pending.some((claim) => sameClaim(claim, group.retired))));
|
|
25
|
+
let size = -1;
|
|
26
|
+
while (size !== keep.size) {
|
|
27
|
+
size = keep.size;
|
|
28
|
+
for (const group of keep) for (const carrier of group.carriers) for (const next of groups) if (sameClaim(next.before, carrier)) keep.add(next);
|
|
29
|
+
}
|
|
30
|
+
const retained = groups.filter((group) => keep.has(group));
|
|
31
|
+
const related = relatedIds(retained);
|
|
32
|
+
return {
|
|
33
|
+
consolidations: retained,
|
|
34
|
+
acknowledgements: acknowledgements.filter((claim) => related.has(claim.id))
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/store/rejected-disputes.ts
|
|
39
|
+
const RejectionsSchema = z.record(z.string().regex(/^[0-9a-f]{64}$/), z.object({
|
|
40
|
+
dispute_id: DisputeIdSchema,
|
|
41
|
+
status: z.literal(409),
|
|
42
|
+
attempts: z.number().int().positive().default(1),
|
|
43
|
+
rejected_at: TimestampSchema
|
|
44
|
+
}));
|
|
45
|
+
const disputeVersion = (dispute) => createHash("sha256").update(JSON.stringify(DisputeSchema.parse(dispute))).digest("hex");
|
|
46
|
+
var RejectedDisputeStore = class {
|
|
47
|
+
context;
|
|
48
|
+
constructor(context) {
|
|
49
|
+
this.context = context;
|
|
50
|
+
}
|
|
51
|
+
async read(includeHistory = false) {
|
|
52
|
+
if (this.context.mode === "solo" && !includeHistory) return {};
|
|
53
|
+
return readYamlOr(this.context.paths.rejectedDisputes, RejectionsSchema, () => ({}));
|
|
54
|
+
}
|
|
55
|
+
async contains(dispute) {
|
|
56
|
+
return Object.hasOwn(await this.read(), disputeVersion(dispute));
|
|
57
|
+
}
|
|
58
|
+
async record(dispute, attempts = 1) {
|
|
59
|
+
if (this.context.mode === "solo") return;
|
|
60
|
+
await withFileLock(`${this.context.paths.rejectedDisputes}.lock`, async () => {
|
|
61
|
+
const records = await this.read();
|
|
62
|
+
const key = disputeVersion(dispute);
|
|
63
|
+
if (Object.hasOwn(records, key)) return;
|
|
64
|
+
records[key] = {
|
|
65
|
+
dispute_id: dispute.id,
|
|
66
|
+
status: 409,
|
|
67
|
+
attempts,
|
|
68
|
+
rejected_at: nowSeconds()
|
|
69
|
+
};
|
|
70
|
+
await writeYamlAtomic(this.context.paths.rejectedDisputes, records, RejectionsSchema, this.context.logger);
|
|
71
|
+
}, { timeoutMs: this.context.lockTimeoutMs });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/store/uploads.ts
|
|
76
|
+
const ConsolidationDeliverySchema = z.object({
|
|
77
|
+
before: ClaimSchema,
|
|
78
|
+
retired: ClaimSchema,
|
|
79
|
+
carriers: z.array(ClaimSchema)
|
|
80
|
+
});
|
|
81
|
+
const PendingUploadsSchema = z.object({
|
|
82
|
+
consolidations: z.array(ConsolidationDeliverySchema).default([]).transform((items) => items.length === 0 ? void 0 : items),
|
|
83
|
+
acknowledgements: z.array(ClaimSchema).default([]).transform((items) => items.length === 0 ? void 0 : items),
|
|
84
|
+
claims: z.array(ClaimSchema).default([]),
|
|
85
|
+
durable_claim_ids: z.array(ClaimIdSchema).default([]).transform((items) => items.length === 0 ? void 0 : [...new Set(items)].sort()),
|
|
86
|
+
disputes: z.array(DisputeSchema).default([])
|
|
87
|
+
});
|
|
88
|
+
var UploadStore = class {
|
|
89
|
+
context;
|
|
90
|
+
constructor(context) {
|
|
91
|
+
this.context = context;
|
|
92
|
+
}
|
|
93
|
+
async read() {
|
|
94
|
+
if (this.context.mode === "solo") return PendingUploadsSchema.parse({});
|
|
95
|
+
return readYamlOr(this.context.paths.pendingUploads, PendingUploadsSchema, () => PendingUploadsSchema.parse({}));
|
|
96
|
+
}
|
|
97
|
+
async save(value) {
|
|
98
|
+
if (this.context.mode === "solo") return;
|
|
99
|
+
await this.modify(() => PendingUploadsSchema.parse(value));
|
|
100
|
+
}
|
|
101
|
+
async persist(value) {
|
|
102
|
+
if (value.claims.length === 0 && value.disputes.length === 0 && !value.consolidations?.length && !value.acknowledgements?.length) await removeFile(this.context.paths.pendingUploads, this.context.logger);
|
|
103
|
+
else await writeYamlAtomic(this.context.paths.pendingUploads, value, PendingUploadsSchema, this.context.logger);
|
|
104
|
+
}
|
|
105
|
+
async modify(update) {
|
|
106
|
+
if (this.context.mode === "solo") return;
|
|
107
|
+
await withFileLock(this.context.paths.pendingUploadsLock, async () => {
|
|
108
|
+
await this.persist(PendingUploadsSchema.parse(await update(await this.read())));
|
|
109
|
+
}, { timeoutMs: this.context.lockTimeoutMs });
|
|
110
|
+
}
|
|
111
|
+
async enqueue(claims, disputes, durable = false, dependencies = []) {
|
|
112
|
+
if (this.context.mode === "solo") return;
|
|
113
|
+
await this.modify(async (pending) => {
|
|
114
|
+
const rejected = await new RejectedDisputeStore(this.context).read();
|
|
115
|
+
const byClaim = new Map(pending.claims.map((claim) => [claim.id, claim]));
|
|
116
|
+
let consolidations = pending.consolidations ?? [];
|
|
117
|
+
for (const value of claims) {
|
|
118
|
+
const claim = ClaimSchema.parse(value);
|
|
119
|
+
const existing = byClaim.get(claim.id);
|
|
120
|
+
if (existing !== void 0 && timestampNanos(effectiveUpdatedAt(claim)) < timestampNanos(effectiveUpdatedAt(existing))) continue;
|
|
121
|
+
consolidations = claim.status === "deprecated" ? consolidations.map((group) => group.retired.id === claim.id ? {
|
|
122
|
+
...group,
|
|
123
|
+
retired: claim
|
|
124
|
+
} : group) : consolidations.filter((group) => group.retired.id !== claim.id);
|
|
125
|
+
byClaim.set(claim.id, claim);
|
|
126
|
+
}
|
|
127
|
+
const byDispute = new Map(pending.disputes.map((dispute) => [dispute.id, dispute]));
|
|
128
|
+
for (const value of disputes) {
|
|
129
|
+
const dispute = DisputeSchema.parse(value);
|
|
130
|
+
if (Object.hasOwn(rejected, disputeVersion(dispute))) continue;
|
|
131
|
+
const existing = byDispute.get(dispute.id);
|
|
132
|
+
if (existing === void 0 || timestampNanos(dispute.created_at) >= timestampNanos(existing.created_at)) byDispute.set(dispute.id, dispute);
|
|
133
|
+
}
|
|
134
|
+
const durableIds = new Set(pending.durable_claim_ids ?? []);
|
|
135
|
+
if (durable) for (const claim of claims) durableIds.add(claim.id);
|
|
136
|
+
for (const dependency of dependencies) if (byClaim.get(dependency.retired.id) !== void 0 && sameClaim(byClaim.get(dependency.retired.id) ?? dependency.before, dependency.retired)) {
|
|
137
|
+
consolidations = consolidations.filter((group) => group.retired.id !== dependency.retired.id);
|
|
138
|
+
consolidations.push(ConsolidationDeliverySchema.parse(dependency));
|
|
139
|
+
}
|
|
140
|
+
return PendingUploadsSchema.parse({
|
|
141
|
+
...pending,
|
|
142
|
+
consolidations,
|
|
143
|
+
claims: [...byClaim.values()].sort((a, b) => a.id.localeCompare(b.id)),
|
|
144
|
+
durable_claim_ids: [...durableIds].filter((id) => byClaim.has(id)).sort(),
|
|
145
|
+
disputes: [...byDispute.values()].sort((a, b) => a.id.localeCompare(b.id))
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async removeDeliveredClaims(delivered) {
|
|
150
|
+
if (this.context.mode === "solo") return;
|
|
151
|
+
const revisions = new Map(delivered.map((claim) => [claim.id, claimRevision(claim)]));
|
|
152
|
+
await this.modify((pending) => {
|
|
153
|
+
const claims = pending.claims.filter((claim) => revisions.get(claim.id) !== claimRevision(claim));
|
|
154
|
+
const ids = new Set(claims.map((claim) => claim.id));
|
|
155
|
+
const acknowledgements = [...pending.acknowledgements ?? []];
|
|
156
|
+
for (const claim of delivered) {
|
|
157
|
+
const index = acknowledgements.findIndex((value) => value.id === claim.id);
|
|
158
|
+
if (index >= 0) acknowledgements.splice(index, 1);
|
|
159
|
+
acknowledgements.push(claim);
|
|
160
|
+
}
|
|
161
|
+
return PendingUploadsSchema.parse({
|
|
162
|
+
...pending,
|
|
163
|
+
...pruneDeliveries(pending.consolidations ?? [], acknowledgements, claims),
|
|
164
|
+
claims,
|
|
165
|
+
durable_claim_ids: pending.durable_claim_ids?.filter((id) => ids.has(id))
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async rebind(previous, revised) {
|
|
170
|
+
if (this.context.mode === "solo") throw new StoreError("conflict", "Team delivery is disabled.");
|
|
171
|
+
await this.modify((pending) => {
|
|
172
|
+
const exact = (group, value) => sameClaim(group.before, value.before) && sameClaim(group.retired, value.retired) && group.carriers.length === value.carriers.length && group.carriers.every((claim, index) => value.carriers[index] !== void 0 && sameClaim(claim, value.carriers[index]));
|
|
173
|
+
if (pending.consolidations?.some((group) => exact(group, revised))) return pending;
|
|
174
|
+
if (!pending.consolidations?.some((group) => exact(group, previous)) || !pending.claims.some((claim) => sameClaim(claim, previous.retired))) throw new StoreError("conflict", "Consolidation dependency changed; review current versions.");
|
|
175
|
+
const claims = pending.claims.filter((claim) => !revised.carriers.some((carrier) => carrier.id === claim.id));
|
|
176
|
+
claims.push(...revised.carriers);
|
|
177
|
+
return PendingUploadsSchema.parse({
|
|
178
|
+
...pending,
|
|
179
|
+
claims,
|
|
180
|
+
durable_claim_ids: [.../* @__PURE__ */ new Set([...pending.durable_claim_ids ?? [], ...revised.carriers.map((claim) => claim.id)])],
|
|
181
|
+
consolidations: [...pending.consolidations.filter((group) => group.retired.id !== revised.retired.id), revised]
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async removeDeliveredDisputes(delivered) {
|
|
186
|
+
if (this.context.mode === "solo") return;
|
|
187
|
+
const encoded = new Set(delivered.map((dispute) => JSON.stringify(DisputeSchema.parse(dispute))));
|
|
188
|
+
await this.modify((pending) => PendingUploadsSchema.parse({
|
|
189
|
+
...pending,
|
|
190
|
+
disputes: pending.disputes.filter((dispute) => !encoded.has(JSON.stringify(dispute)))
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
async withdrawPolicy(policyId) {
|
|
194
|
+
if (this.context.mode === "solo") return;
|
|
195
|
+
await this.modify((pending) => {
|
|
196
|
+
const obsolete = (pending.consolidations ?? []).filter((group) => group.before.source_claim_ids.includes(policyId) || group.retired.source_claim_ids.includes(policyId));
|
|
197
|
+
const obsoleteIds = new Set(obsolete.map((group) => group.retired.id));
|
|
198
|
+
const carriers = new Set(obsolete.flatMap((group) => group.carriers.map((claim) => claim.id)));
|
|
199
|
+
const retained = (pending.consolidations ?? []).filter((group) => !obsoleteIds.has(group.retired.id));
|
|
200
|
+
const stillNeeded = new Set(retained.flatMap((group) => group.carriers.map((claim) => claim.id)));
|
|
201
|
+
return PendingUploadsSchema.parse({
|
|
202
|
+
...pending,
|
|
203
|
+
consolidations: retained,
|
|
204
|
+
claims: pending.claims.filter((claim) => !carriers.has(claim.id) || stillNeeded.has(claim.id) || pending.durable_claim_ids?.includes(claim.id) || claim.source_claim_ids.some((source) => source === policyId))
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
//#endregion
|
|
210
|
+
export { disputeVersion as a, RejectedDisputeStore as i, PendingUploadsSchema as n, consolidationReady as o, UploadStore as r, relatedIds as s, ConsolidationDeliverySchema as t };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { S as LockTimeoutError, _ as JobError, b as Preempted, g as DreamYield, h as DreamStopped, t as acquireFileLease, x as jobPriority } from "./lock-DbmlKOoX.js";
|
|
2
|
+
import { t as DreamStore } from "./checkpoint-RgcdqifN.js";
|
|
3
|
+
import { n as runnableJob, t as JobQueue } from "./queue-M917xHPS.js";
|
|
4
|
+
//#region src/worker/worker.ts
|
|
5
|
+
var DurableWorker = class {
|
|
6
|
+
context;
|
|
7
|
+
options;
|
|
8
|
+
queue;
|
|
9
|
+
handlers = /* @__PURE__ */ new Map();
|
|
10
|
+
lease;
|
|
11
|
+
active;
|
|
12
|
+
timer;
|
|
13
|
+
ticking;
|
|
14
|
+
closed = false;
|
|
15
|
+
started = false;
|
|
16
|
+
nextAcquire = 0;
|
|
17
|
+
constructor(context, options = {}) {
|
|
18
|
+
this.context = context;
|
|
19
|
+
this.options = options;
|
|
20
|
+
this.queue = new JobQueue(context);
|
|
21
|
+
}
|
|
22
|
+
register(kind, handler) {
|
|
23
|
+
this.handlers.set(kind, handler);
|
|
24
|
+
this.wake(true);
|
|
25
|
+
return () => {
|
|
26
|
+
if (this.handlers.get(kind) !== handler) return;
|
|
27
|
+
this.handlers.delete(kind);
|
|
28
|
+
if (this.active?.job.kind === kind && !this.active.prepared) this.active.abort.abort(new JobError("suspended", "后台处理器已暂停,任务保留。"));
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
supports(kind) {
|
|
32
|
+
return this.handlers.has(kind);
|
|
33
|
+
}
|
|
34
|
+
canRun(job) {
|
|
35
|
+
return runnableJob(job, this.handlers);
|
|
36
|
+
}
|
|
37
|
+
async start() {
|
|
38
|
+
if (this.started || this.closed) return;
|
|
39
|
+
this.started = true;
|
|
40
|
+
this.timer = setInterval(() => {
|
|
41
|
+
this.wake();
|
|
42
|
+
}, this.options.pollMs ?? 1e3);
|
|
43
|
+
this.timer.unref();
|
|
44
|
+
this.wake();
|
|
45
|
+
await Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
wake(force = false) {
|
|
48
|
+
if (!this.started || this.closed || this.ticking !== void 0) return;
|
|
49
|
+
if (force) this.nextAcquire = 0;
|
|
50
|
+
const tick = this.tick().catch(() => {
|
|
51
|
+
this.context.logger.warn("Background worker could not read or commit its local queue.");
|
|
52
|
+
});
|
|
53
|
+
this.ticking = tick;
|
|
54
|
+
tick.finally(() => {
|
|
55
|
+
if (this.ticking === tick) this.ticking = void 0;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async enqueue(kind, payload, sessionId) {
|
|
59
|
+
const job = await this.queue.enqueue(kind, payload, sessionId);
|
|
60
|
+
if (this.canRun(job) && this.active?.job.kind === "dream" && !this.active.prepared && jobPriority[kind] < jobPriority.dream) this.active.abort.abort(new DreamYield());
|
|
61
|
+
if (this.canRun(job) && kind === "finalize" && this.active?.job.kind === "recap" && this.active.job.sessionId === sessionId && !this.active.prepared) this.active.abort.abort(new Preempted());
|
|
62
|
+
this.wake(true);
|
|
63
|
+
return job;
|
|
64
|
+
}
|
|
65
|
+
async retry(id) {
|
|
66
|
+
const job = await this.queue.retry(id);
|
|
67
|
+
this.wake(true);
|
|
68
|
+
return job;
|
|
69
|
+
}
|
|
70
|
+
cancelDream(reason = new DreamStopped()) {
|
|
71
|
+
if (this.active?.job.kind === "dream") this.active.abort.abort(reason);
|
|
72
|
+
}
|
|
73
|
+
async tick() {
|
|
74
|
+
if (this.lease === void 0) {
|
|
75
|
+
if (Date.now() < this.nextAcquire) return;
|
|
76
|
+
try {
|
|
77
|
+
this.lease = await acquireFileLease(this.context.paths.workerLock, {
|
|
78
|
+
timeoutMs: 0,
|
|
79
|
+
staleMs: this.options.staleMs
|
|
80
|
+
});
|
|
81
|
+
await this.queue.recoverRunning();
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (this.lease !== void 0) {
|
|
84
|
+
await this.lease.release();
|
|
85
|
+
this.lease = void 0;
|
|
86
|
+
}
|
|
87
|
+
this.nextAcquire = Date.now() + (this.options.takeoverMs ?? 6e4);
|
|
88
|
+
if (!(error instanceof LockTimeoutError)) throw error;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
while (!this.closed) {
|
|
93
|
+
this.lease.check();
|
|
94
|
+
await new DreamStore(this.context).recover();
|
|
95
|
+
const job = await this.queue.claim(new Set(this.handlers.keys()));
|
|
96
|
+
if (job === null) return;
|
|
97
|
+
const handler = this.handlers.get(job.kind);
|
|
98
|
+
if (handler === void 0) {
|
|
99
|
+
await this.queue.settle(job, "queued");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const active = {
|
|
103
|
+
job,
|
|
104
|
+
abort: new AbortController(),
|
|
105
|
+
prepared: false
|
|
106
|
+
};
|
|
107
|
+
this.active = active;
|
|
108
|
+
let checking = false;
|
|
109
|
+
const monitor = setInterval(() => {
|
|
110
|
+
if (checking || active.prepared || job.kind !== "recap" && job.kind !== "dream") return;
|
|
111
|
+
checking = true;
|
|
112
|
+
this.queue.list().then((jobs) => {
|
|
113
|
+
if (job.kind === "recap" && jobs.some((candidate) => candidate.kind === "finalize" && candidate.sessionId === job.sessionId && this.canRun(candidate))) active.abort.abort(new Preempted());
|
|
114
|
+
if (job.kind === "dream" && jobs.some((candidate) => candidate.id === job.id && candidate.payload["paused"] === true)) active.abort.abort(new DreamStopped());
|
|
115
|
+
if (job.kind === "dream" && jobs.some((candidate) => this.canRun(candidate) && jobPriority[candidate.kind] < jobPriority.dream)) active.abort.abort(new DreamYield());
|
|
116
|
+
}).catch(() => {
|
|
117
|
+
active.abort.abort(new JobError("storage", "Cannot inspect preemption queue."));
|
|
118
|
+
}).finally(() => {
|
|
119
|
+
checking = false;
|
|
120
|
+
});
|
|
121
|
+
}, this.options.pollMs ?? 1e3);
|
|
122
|
+
monitor.unref();
|
|
123
|
+
try {
|
|
124
|
+
const result = await handler(job, {
|
|
125
|
+
signal: active.abort.signal,
|
|
126
|
+
prepared: () => {
|
|
127
|
+
active.prepared = true;
|
|
128
|
+
},
|
|
129
|
+
committed: () => {
|
|
130
|
+
active.prepared = false;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
this.lease.check();
|
|
134
|
+
await this.queue.settle(job, "succeeded", result === void 0 ? {} : { result });
|
|
135
|
+
} catch (error) {
|
|
136
|
+
const reason = active.abort.signal.aborted ? active.abort.signal.reason : error;
|
|
137
|
+
if (active.prepared) await this.queue.settle(job, job.attempts < 5 ? "queued" : "failed", {
|
|
138
|
+
lastErrorKind: "storage",
|
|
139
|
+
lastError: "本地提交待 checkpoint 恢复;请检查存储后重试任务。",
|
|
140
|
+
nextRunAt: Date.now() + 1e3
|
|
141
|
+
});
|
|
142
|
+
else if (reason instanceof DreamStopped || reason instanceof DreamYield) await this.queue.settle(job, "queued", { attempts: Math.max(0, job.attempts - 1) });
|
|
143
|
+
else if (this.closed || reason instanceof JobError && reason.kind === "suspended") await this.queue.settle(job, "queued");
|
|
144
|
+
else if (reason instanceof Preempted) await this.queue.settle(job, "succeeded", { result: { skipped: "superseded" } });
|
|
145
|
+
else {
|
|
146
|
+
const retryable = reason instanceof JobError && reason.retryable && job.attempts < 5;
|
|
147
|
+
await this.queue.settle(job, retryable ? "queued" : "failed", {
|
|
148
|
+
lastErrorKind: reason instanceof JobError ? reason.kind : "storage",
|
|
149
|
+
lastError: reason instanceof JobError ? reason.message + (reason.retryable && !retryable ? " 已达到自动重试上限,请修正原因后手动重试任务。" : "") : "后台任务失败;请检查本地存储和模型路由后重试。",
|
|
150
|
+
...retryable ? { nextRunAt: Date.now() + Math.max((this.options.retryBaseMs ?? 500) * 2 ** (job.attempts - 1), reason instanceof JobError ? reason.retryAfterMs ?? 0 : 0) } : {}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
} finally {
|
|
154
|
+
clearInterval(monitor);
|
|
155
|
+
this.active = void 0;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async close() {
|
|
160
|
+
this.closed = true;
|
|
161
|
+
if (this.timer !== void 0) clearInterval(this.timer);
|
|
162
|
+
this.active?.abort.abort(new JobError("disposed", "Worker disposed."));
|
|
163
|
+
const finish = async () => {
|
|
164
|
+
await this.ticking;
|
|
165
|
+
if (this.lease !== void 0) {
|
|
166
|
+
await this.lease.release();
|
|
167
|
+
this.lease = void 0;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const completion = finish();
|
|
171
|
+
let timer;
|
|
172
|
+
await Promise.race([completion, new Promise((resolve) => {
|
|
173
|
+
timer = setTimeout(() => {
|
|
174
|
+
this.context.logger.warn("Worker is still reaching a safe point; lease retained until completion.");
|
|
175
|
+
resolve();
|
|
176
|
+
}, 1e4);
|
|
177
|
+
})]);
|
|
178
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
179
|
+
completion.catch(() => {
|
|
180
|
+
this.context.logger.warn("Worker lease cleanup failed.");
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
//#endregion
|
|
185
|
+
export { DurableWorker as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN Commands","description":"Inspect and import knowledge, check and retry jobs, and control background work."}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN 管理命令","description":"提供知识查询、导入、任务状态、重试和后台处理命令。"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN Dream","description":"Clean up and consolidate knowledge, with optional bounded evidence calibration."}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN 知识整理","description":"清理与整合已有知识,可选启用受限证据校准。"}}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN Knowledge Formation","description":"Extract reusable knowledge from task records through Recap and Finalize."}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN 知识形成","description":"通过 Recap 与 Finalize 从任务记录中提炼可复用知识。"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN Team Inbox","description":"Pull team suggestions, internalize them locally, and deliver results reliably."}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN 团队收件箱","description":"拉取团队建议,在本地复核内化并可靠投递结果。"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN Knowledge Store","description":"Manage local Claims, Traces, durable jobs, and team connections."}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN 知识存储","description":"管理本地 Claim、Trace、持久任务与团队连接。"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN Knowledge Context","description":"Freeze session knowledge catalogs and surface sources and changes."}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN 知识上下文","description":"为会话冻结知识目录,提示可引用来源与知识变化。"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN Knowledge Tools","description":"Read and edit Claims, inspect Traces, and consult the team Router."}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"ACN 知识工具","description":"读取和编辑 Claim、查看 Trace,并查询团队 Router。"}}
|