chore(deno): migrate toolchain from Node 24 + pnpm to Deno 2.9.7 + TypeScript 7.0.2 (W1.5)
- root deno.json workspace (nodeModulesDir auto), npm versions registered once in imports, deno.lock; remove pnpm-lock/pnpm-workspace/root package.json; members keep minimal package.json (name/type/exports) - tasks: dev, typecheck (tsc 7.0.2 per member + deno check), lint/fmt (biome, useImportExtensions), test (vitest via deno), check:tokens, build (web + deno compile), ci, db:migrate/reset, gen:types - tsconfig base moved to config/ (no root tsconfig.json); deno types -> types/deno.d.ts; web drops baseUrl - server: Deno.serve entry with graceful shutdown, --role migrate|preflight|probe, WEB_ROOT static SPA hosting; drop @hono/node-server, tsx, esbuild build.mjs - logger: redact child() bindings and serialize err by message/stack; sync stdout destination; tests - relative imports get explicit extensions (sites/mp-sync paths left for follow-up) - crash-recovery tests spawn `deno run -A`; tasks tests use unique per-file schemas - single-container Dockerfile + entrypoint (migrate -> preflight -> api+worker watchdog), docker-compose.yml - docs: README, runbook, ADR-001 superseded, plan §1 validation row Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
d9f2af2f3c
commit
304feea141
226 files changed
+6601
-8620
No files matched your search
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "@umt/adapters",
|
||||
"version": "0.0.0",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"tasks": {
|
||||
"test": "deno run -A npm:vitest run",
|
||||
"typecheck": "deno run -A npm:typescript/tsc --noEmit -p tsconfig.json"
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,8 @@
|
||||
{
|
||||
"name": "@umt/adapters",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc -p tsconfig.json",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"cheerio": "^1.2.0",
|
||||
"fast-xml-parser": "^5.11.1",
|
||||
"nunjucks": "^3.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/nunjucks": "^3.2.6",
|
||||
"@umt/testkit": "workspace:*"
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
identitiesCompatible,
|
||||
MediaServerRegistry,
|
||||
providerIdentity,
|
||||
} from "./index";
|
||||
} from "./index.ts";
|
||||
|
||||
let mocks: MockEmby[] = [];
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from "./client";
|
||||
export * from "./client.ts";
|
||||
@@ -6,7 +6,7 @@ import { link, lstat, mkdir, open, readdir, rename, stat, unlink, utimes } from
|
||||
import { basename, dirname, join } from "node:path";
|
||||
import { Transform } from "node:stream";
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import { errnoOf, FsError, toFsError } from "./errors";
|
||||
import { errnoOf, FsError, toFsError } from "./errors.ts";
|
||||
|
||||
export type VerifyMethod = "size" | "sha256" | "sample";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// 本项目新增:ffprobe 封装与 statfs 磁盘用量(REQ §8.2、§8.4.1);失败一律返回 unknown。
|
||||
import { execFile } from "node:child_process";
|
||||
import { statfs } from "node:fs/promises";
|
||||
import { errnoOf } from "./errors";
|
||||
import { errnoOf } from "./errors.ts";
|
||||
|
||||
export interface ProbeVideo {
|
||||
codec?: string;
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
scanIncremental,
|
||||
statSafe,
|
||||
sweepStalePartials,
|
||||
} from "./index";
|
||||
} from "./index.ts";
|
||||
|
||||
const trees: TempTree[] = [];
|
||||
async function tree(...a: Parameters<typeof createTempTree>) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export * from "./copy";
|
||||
export * from "./errors";
|
||||
export * from "./ffprobe";
|
||||
export * from "./move";
|
||||
export * from "./scan";
|
||||
export * from "./stat";
|
||||
export * from "./copy.ts";
|
||||
export * from "./errors.ts";
|
||||
export * from "./ffprobe.ts";
|
||||
export * from "./move.ts";
|
||||
export * from "./scan.ts";
|
||||
export * from "./stat.ts";
|
||||
@@ -2,8 +2,8 @@
|
||||
// 调整:EXDEV 显式返回不降级;跨设备拆为 copy→verify→delete_source 可重入三步,删源失败 = attention。
|
||||
import { link, lstat, rename, stat, unlink } from "node:fs/promises";
|
||||
import { dirname } from "node:path";
|
||||
import { type CopyOptions, copyWithVerify, filesMatch, type VerifyMethod } from "./copy";
|
||||
import { errnoOf, FsError, toFsError } from "./errors";
|
||||
import { type CopyOptions, copyWithVerify, filesMatch, type VerifyMethod } from "./copy.ts";
|
||||
import { errnoOf, FsError, toFsError } from "./errors.ts";
|
||||
|
||||
export type MoveResult = { status: "moved" } | { status: "exdev" } | { status: "exists" };
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
import type { Dirent } from "node:fs";
|
||||
import { lstat, readdir } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { errnoOf } from "./errors";
|
||||
import { checkRoot, DEFAULT_ROOT_SENTINEL } from "./stat";
|
||||
import { errnoOf } from "./errors.ts";
|
||||
import { checkRoot, DEFAULT_ROOT_SENTINEL } from "./stat.ts";
|
||||
|
||||
export interface ScanEntry {
|
||||
/** 相对根目录的路径,/ 分隔 */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// 本项目新增(REQ §8.2 挂载根哨兵);MP 无对应实现。
|
||||
import { lstat, stat, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { errnoOf } from "./errors";
|
||||
import { errnoOf } from "./errors.ts";
|
||||
|
||||
export const DEFAULT_ROOT_SENTINEL = ".uhd-root";
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// @umt/adapters 公开入口;W1 起在此导出实现
|
||||
export const PACKAGE_NAME = "@umt/adapters";
|
||||
export * from "./emby";
|
||||
export * from "./fs";
|
||||
export * from "./qbittorrent";
|
||||
export * from "./rss";
|
||||
export * from "./sites";
|
||||
export * from "./tmdb";
|
||||
export * from "./emby/index.ts";
|
||||
export * from "./fs/index.ts";
|
||||
export * from "./qbittorrent/index.ts";
|
||||
export * from "./rss/index.ts";
|
||||
export * from "./sites/index.ts";
|
||||
export * from "./tmdb/index.ts";
|
||||
@@ -5,9 +5,9 @@
|
||||
* 叠加:多实例、错误分类(DownloaderError)、提交幂等(本地 infohash 预查 + 收单超时按 hash 回查)。
|
||||
*/
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { DownloaderError, type DownloaderErrorKind } from "./errors";
|
||||
import { isDownloadComplete, mapQbState, type QbObservedState } from "./state";
|
||||
import { BencodeError, parseMagnet, parseTorrent } from "./torrent";
|
||||
import { DownloaderError, type DownloaderErrorKind } from "./errors.ts";
|
||||
import { isDownloadComplete, mapQbState, type QbObservedState } from "./state.ts";
|
||||
import { BencodeError, parseMagnet, parseTorrent } from "./torrent.ts";
|
||||
|
||||
export interface QbInstanceConfig {
|
||||
/** 本系统内的下载器实例 ID(downloader_instance.id) */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export * from "./client";
|
||||
export * from "./errors";
|
||||
export * from "./paths";
|
||||
export * from "./state";
|
||||
export * from "./torrent";
|
||||
export * from "./client.ts";
|
||||
export * from "./errors.ts";
|
||||
export * from "./paths.ts";
|
||||
export * from "./state.ts";
|
||||
export * from "./torrent.ts";
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createMockQb, type MockQb, makeMagnet, makeTorrent } from "@umt/testkit";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { createQbClient, DownloaderError, isDownloadComplete, mapQbState, parseMagnet, parseTorrent } from "./index";
|
||||
import { fromDownloaderPath, toDownloaderPath } from "./paths";
|
||||
import { createQbClient, DownloaderError, isDownloadComplete, mapQbState, parseMagnet, parseTorrent } from "./index.ts";
|
||||
import { fromDownloaderPath, toDownloaderPath } from "./paths.ts";
|
||||
|
||||
let mock: MockQb | null = null;
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { FeedCursor, FeedItem } from "./types";
|
||||
import type { FeedCursor, FeedItem } from "./types.ts";
|
||||
|
||||
export function emptyFeedCursor(): FeedCursor {
|
||||
return { lastGuidSet: [], digests: {}, lastFetchedAt: null };
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* RSS 抓取。迁移自 MP `app/application/rss.py RssHelper.parse/_parse_impl`(GET + UA + 自定义头,非 200 视为失败,
|
||||
* 大小上限后再解析);条件请求、退避、Retry-After、熔断、脱敏为任务书新增要求(MP 无)。
|
||||
*/
|
||||
import { parseFeed } from "./parse";
|
||||
import { redactText, redactUrl } from "./redact";
|
||||
import { FeedError, type FeedFetchResult, type FeedFetchState } from "./types";
|
||||
import { parseFeed } from "./parse.ts";
|
||||
import { redactText, redactUrl } from "./redact.ts";
|
||||
import { FeedError, type FeedFetchResult, type FeedFetchState } from "./types.ts";
|
||||
|
||||
export interface RssFetcherOptions {
|
||||
fetch?: typeof globalThis.fetch;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { type ApplyFeedOptions, type ApplyFeedResult, applyFeedItems, emptyFeedCursor } from "./cursor";
|
||||
export { type ApplyFeedOptions, type ApplyFeedResult, applyFeedItems, emptyFeedCursor } from "./cursor.ts";
|
||||
export {
|
||||
computeBackoffMs,
|
||||
createRssFetcher,
|
||||
@@ -8,16 +8,16 @@ export {
|
||||
type RssFetcher,
|
||||
type RssFetcherOptions,
|
||||
resetFeedCircuit,
|
||||
} from "./fetch";
|
||||
} from "./fetch.ts";
|
||||
export {
|
||||
assertNoDtdEntities,
|
||||
decodeXmlEntities,
|
||||
type ParseFeedOptions,
|
||||
parseFeed,
|
||||
RSS_EXPIRED_MESSAGES,
|
||||
} from "./parse";
|
||||
export { extractSecretParams, REDACTED, redactText, redactUrl, SENSITIVE_QUERY_KEYS, unredactUrl } from "./redact";
|
||||
export { buildRssLinkRequest, extractRssLink, RSS_LINK_CONF, type RssLinkConf, rssSiteDomain } from "./rss-link";
|
||||
} from "./parse.ts";
|
||||
export { extractSecretParams, REDACTED, redactText, redactUrl, SENSITIVE_QUERY_KEYS, unredactUrl } from "./redact.ts";
|
||||
export { buildRssLinkRequest, extractRssLink, RSS_LINK_CONF, type RssLinkConf, rssSiteDomain } from "./rss-link.ts";
|
||||
export {
|
||||
type FeedCursor,
|
||||
FeedError,
|
||||
@@ -26,4 +26,4 @@ export {
|
||||
type FeedFetchState,
|
||||
type FeedItem,
|
||||
type ParsedFeed,
|
||||
} from "./types";
|
||||
} from "./types.ts";
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { XMLParser } from "fast-xml-parser";
|
||||
import { redactUrl } from "./redact";
|
||||
import { FeedError, type FeedItem, type ParsedFeed } from "./types";
|
||||
import { redactUrl } from "./redact.ts";
|
||||
import { FeedError, type FeedItem, type ParsedFeed } from "./types.ts";
|
||||
|
||||
export interface ParseFeedOptions {
|
||||
/** 条目上限,超出截断并置 truncated(默认 1000,同 MP) */
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
redactUrl,
|
||||
resetFeedCircuit,
|
||||
unredactUrl,
|
||||
} from "./index";
|
||||
} from "./index.ts";
|
||||
|
||||
const PASSKEY = "abcdef0123456789secret";
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* match/match_multi 的匹配链见 match.ts。
|
||||
* 调整:网络/鉴权/限流错误以 TmdbError 抛出而非返回 None,调用方不得把"查询失败"当成"没有结果"。
|
||||
*/
|
||||
import { RequestLimiter, TtlLruCache } from "./cache";
|
||||
import { RequestLimiter, TtlLruCache } from "./cache.ts";
|
||||
|
||||
export type TmdbErrorKind = "auth" | "network" | "timeout" | "notfound" | "rate" | "protocol";
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { RequestLimiter, TtlLruCache } from "./cache";
|
||||
export * from "./client";
|
||||
export * from "./match";
|
||||
export { RequestLimiter, TtlLruCache } from "./cache.ts";
|
||||
export * from "./client.ts";
|
||||
export * from "./match.ts";
|
||||
@@ -10,7 +10,7 @@
|
||||
* 调整:MP 查询失败返回 None 后继续下一步;这里 TMDB 错误直接抛出,避免把"查不到"与"查询失败"混为一谈。
|
||||
* 未迁移:剧集组(group_seasons)季年份判断。打分/身份判定在 packages/domain。
|
||||
*/
|
||||
import type { MediaEntityType, MetadataCandidate, TmdbClient } from "./client";
|
||||
import type { MediaEntityType, MetadataCandidate, TmdbClient } from "./client.ts";
|
||||
|
||||
const PUNCT = /[、.。,,·::;;!!??'’"“”()()[\]【】「」\-—―+|\\_/&#~~]/g;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
type TmdbConfig,
|
||||
TmdbError,
|
||||
yearRange,
|
||||
} from "./index";
|
||||
} from "./index.ts";
|
||||
|
||||
let mock: MockTmdb | null = null;
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { PACKAGE_NAME } from "../src";
|
||||
import { PACKAGE_NAME } from "../src/index.ts";
|
||||
|
||||
it("包入口可加载", () => {
|
||||
expect(PACKAGE_NAME).toBe("@umt/adapters");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"extends": "../../config/tsconfig.base.json",
|
||||
"include": ["src", "test"]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "@umt/agent",
|
||||
"version": "0.0.0",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"tasks": {
|
||||
"test": "deno run -A npm:vitest run",
|
||||
"typecheck": "deno run -A npm:typescript/tsc --noEmit -p tsconfig.json"
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,8 @@
|
||||
{
|
||||
"name": "@umt/agent",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc -p tsconfig.json",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-agent-core": "0.87.1",
|
||||
"@earendil-works/pi-ai": "0.87.1",
|
||||
"@umt/contracts": "workspace:*",
|
||||
"typebox": "1.3.27",
|
||||
"zod": "^4.6.5"
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { z } from "zod";
|
||||
import { summarizeForLog } from "../redact";
|
||||
import { CapabilityError, isCapabilityError } from "./errors";
|
||||
import { capabilityIdToToolName, isCapabilityId } from "./tool-name";
|
||||
import { summarizeForLog } from "../redact.ts";
|
||||
import { CapabilityError, isCapabilityError } from "./errors.ts";
|
||||
import { capabilityIdToToolName, isCapabilityId } from "./tool-name.ts";
|
||||
import {
|
||||
type AuditSink,
|
||||
type AuthorizationChecker,
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
type HandlerContext,
|
||||
type IdempotencyKeyGenerator,
|
||||
type InvokeContext,
|
||||
} from "./types";
|
||||
} from "./types.ts";
|
||||
|
||||
export interface RegisteredCapability {
|
||||
descriptor: CapabilityDescriptor;
|
||||
|
||||
+11
-11
@@ -1,16 +1,16 @@
|
||||
// @umt/agent 公开入口。Pi SDK 类型只出现在 src/pi/*,这里只导出本包自有接口。
|
||||
export const PACKAGE_NAME = "@umt/agent";
|
||||
|
||||
export { CapabilityError, type CapabilityErrorCode, isCapabilityError } from "./capability/errors";
|
||||
export { CapabilityError, type CapabilityErrorCode, isCapabilityError } from "./capability/errors.ts";
|
||||
export {
|
||||
CapabilityRegistry,
|
||||
type CapabilityRegistryOptions,
|
||||
defaultIdempotencyKey,
|
||||
type RegisteredCapability,
|
||||
stableStringify,
|
||||
} from "./capability/registry";
|
||||
export { capabilityIdToToolName, isCapabilityId, toolNameToCapabilityId } from "./capability/tool-name";
|
||||
export * from "./capability/types";
|
||||
} from "./capability/registry.ts";
|
||||
export { capabilityIdToToolName, isCapabilityId, toolNameToCapabilityId } from "./capability/tool-name.ts";
|
||||
export * from "./capability/types.ts";
|
||||
export {
|
||||
type CreateFakeRuntimeOptions,
|
||||
createFakeRuntime,
|
||||
@@ -21,16 +21,16 @@ export {
|
||||
type FakeStep,
|
||||
type FakeToolCall,
|
||||
type FakeToolResult,
|
||||
} from "./pi/fake";
|
||||
} from "./pi/fake.ts";
|
||||
export {
|
||||
checkToolCall,
|
||||
DEFAULT_COMPACTION_INSTRUCTIONS,
|
||||
PiAgentRuntime,
|
||||
type PiAgentRuntimeOptions,
|
||||
} from "./pi/runtime";
|
||||
export { sessionPathFor } from "./pi/session";
|
||||
export { isSensitiveKey, REDACTED, redactForModel, redactString, summarizeForLog } from "./redact";
|
||||
export * from "./runtime/port";
|
||||
} from "./pi/runtime.ts";
|
||||
export { sessionPathFor } from "./pi/session.ts";
|
||||
export { isSensitiveKey, REDACTED, redactForModel, redactString, summarizeForLog } from "./redact.ts";
|
||||
export * from "./runtime/port.ts";
|
||||
export {
|
||||
type AgentSettings,
|
||||
AgentSettingsSchema,
|
||||
@@ -39,5 +39,5 @@ export {
|
||||
type ResolvedAgentSettings,
|
||||
resolveAgentSettings,
|
||||
THINKING_LEVELS,
|
||||
} from "./settings";
|
||||
export { buildSystemPrompt, type SystemPromptInput } from "./system-prompt";
|
||||
} from "./settings.ts";
|
||||
export { buildSystemPrompt, type SystemPromptInput } from "./system-prompt.ts";
|
||||
@@ -12,10 +12,10 @@ import {
|
||||
type Message,
|
||||
type TranscriptContext,
|
||||
} from "@earendil-works/pi-ai";
|
||||
import type { CapabilityRegistry } from "../capability/registry";
|
||||
import { capabilityIdToToolName, toolNameToCapabilityId } from "../capability/tool-name";
|
||||
import type { ResolvedPiModel } from "./model";
|
||||
import { PiAgentRuntime, type PiAgentRuntimeOptions } from "./runtime";
|
||||
import type { CapabilityRegistry } from "../capability/registry.ts";
|
||||
import { capabilityIdToToolName, toolNameToCapabilityId } from "../capability/tool-name.ts";
|
||||
import type { ResolvedPiModel } from "./model.ts";
|
||||
import { PiAgentRuntime, type PiAgentRuntimeOptions } from "./runtime.ts";
|
||||
|
||||
/** 前面各步工具调用的结果(按发生顺序),供脚本根据结果决定下一步 */
|
||||
export interface FakeToolResult {
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { CompactionSettings } from "@earendil-works/pi-agent-core";
|
||||
import { type Api, createModels, createProvider, type Model, type MutableModels } from "@earendil-works/pi-ai";
|
||||
import { anthropicMessagesApi } from "@earendil-works/pi-ai/api/anthropic-messages.lazy";
|
||||
import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
|
||||
import type { ResolvedAgentSettings } from "../settings";
|
||||
import type { ResolvedAgentSettings } from "../settings.ts";
|
||||
|
||||
/** Pi 侧需要的模型装配结果(仅在 src/pi/* 内部流转) */
|
||||
export interface ResolvedPiModel {
|
||||
|
||||
@@ -11,11 +11,11 @@ import {
|
||||
} from "@earendil-works/pi-agent-core";
|
||||
import type { Usage } from "@earendil-works/pi-ai";
|
||||
import type { TSchema } from "typebox";
|
||||
import { isCapabilityError } from "../capability/errors";
|
||||
import type { CapabilityRegistry, RegisteredCapability } from "../capability/registry";
|
||||
import { toolNameToCapabilityId } from "../capability/tool-name";
|
||||
import { redactForModel, redactString, summarizeForLog } from "../redact";
|
||||
import { EventChannel } from "../runtime/event-channel";
|
||||
import { isCapabilityError } from "../capability/errors.ts";
|
||||
import type { CapabilityRegistry, RegisteredCapability } from "../capability/registry.ts";
|
||||
import { toolNameToCapabilityId } from "../capability/tool-name.ts";
|
||||
import { redactForModel, redactString, summarizeForLog } from "../redact.ts";
|
||||
import { EventChannel } from "../runtime/event-channel.ts";
|
||||
import {
|
||||
type AgentEvent,
|
||||
type AgentEventBody,
|
||||
@@ -26,10 +26,10 @@ import {
|
||||
type CreateRunSpec,
|
||||
emptyUsage,
|
||||
type RunOutcome,
|
||||
} from "../runtime/port";
|
||||
import { type ResolvedAgentSettings, resolveAgentSettings } from "../settings";
|
||||
import { compactionFromSettings, type PiModelResolver, resolveModelFromSettings } from "./model";
|
||||
import { openRunSession } from "./session";
|
||||
} from "../runtime/port.ts";
|
||||
import { type ResolvedAgentSettings, resolveAgentSettings } from "../settings.ts";
|
||||
import { compactionFromSettings, type PiModelResolver, resolveModelFromSettings } from "./model.ts";
|
||||
import { openRunSession } from "./session.ts";
|
||||
|
||||
export interface PiAgentRuntimeOptions {
|
||||
registry: CapabilityRegistry;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { CapabilityScope } from "../capability/types";
|
||||
import type { AgentSettings } from "../settings";
|
||||
import type { CapabilityScope } from "../capability/types.ts";
|
||||
import type { AgentSettings } from "../settings.ts";
|
||||
|
||||
/** 本包对外的用量统计(与 SDK 类型解耦) */
|
||||
export interface AgentUsage {
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
// 子进程:启动 run,download.submit 执行中挂起;父进程收到 SUBMIT_STARTED 后 SIGKILL 本进程。
|
||||
import { createFakeRuntime } from "../../src";
|
||||
import { makeFixture, settings } from "../helpers";
|
||||
import { crashScript, RUN_ID } from "./crash-script";
|
||||
import { createFakeRuntime } from "../../src/index.ts";
|
||||
import { makeFixture, settings } from "../helpers.ts";
|
||||
import { crashScript, RUN_ID } from "./crash-script.ts";
|
||||
|
||||
const sessionDir = process.argv[2]!;
|
||||
const fx = makeFixture({ slowMs: 60_000 });
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import type { FakeScript } from "../../src";
|
||||
import type { FakeScript } from "../../src/index.ts";
|
||||
|
||||
export const RUN_ID = "run-crash-1";
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
CapabilityRegistry,
|
||||
FAKE_AGENT_SETTINGS,
|
||||
type InvokeContext,
|
||||
} from "../src";
|
||||
} from "../src/index.ts";
|
||||
|
||||
export interface Fixture {
|
||||
registry: CapabilityRegistry;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildSystemPrompt, REDACTED, redactForModel, redactString, summarizeForLog } from "../src";
|
||||
import { buildSystemPrompt, REDACTED, redactForModel, redactString, summarizeForLog } from "../src/index.ts";
|
||||
|
||||
describe("redactForModel", () => {
|
||||
it("遮蔽敏感键、含 passkey 的 URL、Bearer、请求头、URL 账号密码", () => {
|
||||
|
||||
@@ -6,8 +6,8 @@ import {
|
||||
capabilityIdToToolName,
|
||||
defaultIdempotencyKey,
|
||||
toolNameToCapabilityId,
|
||||
} from "../src";
|
||||
import { ctx, makeFixture } from "./helpers";
|
||||
} from "../src/index.ts";
|
||||
import { ctx, makeFixture } from "./helpers.ts";
|
||||
|
||||
describe("能力 ID ↔ 工具名", () => {
|
||||
it("双向映射且无歧义", () => {
|
||||
|
||||
@@ -9,9 +9,9 @@ import {
|
||||
checkToolCall,
|
||||
createFakeRuntime,
|
||||
type FakeScript,
|
||||
} from "../src";
|
||||
import { crashScript, RUN_ID } from "./fixtures/crash-script";
|
||||
import { type Fixture, makeFixture, settings, tempDir, types } from "./helpers";
|
||||
} from "../src/index.ts";
|
||||
import { crashScript, RUN_ID } from "./fixtures/crash-script.ts";
|
||||
import { type Fixture, makeFixture, settings, tempDir, types } from "./helpers.ts";
|
||||
|
||||
const opened: AgentRun[] = [];
|
||||
afterEach(async () => {
|
||||
@@ -276,10 +276,14 @@ describe("PiAgentRuntime + FakeModelProvider", () => {
|
||||
|
||||
it("JSONL 恢复:子进程在 download.submit 执行中被 SIGKILL,新进程 resume 得到“结果未知”且不重复提交", async () => {
|
||||
const sessionDir = await tempDir();
|
||||
const child = spawn(process.execPath, ["--import", "tsx", join(__dirname, "fixtures/crash-run.ts"), sessionDir], {
|
||||
cwd: join(__dirname, ".."),
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
["run", "-A", join(import.meta.dirname!, "fixtures/crash-run.ts"), sessionDir],
|
||||
{
|
||||
cwd: join(import.meta.dirname!, ".."),
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
},
|
||||
);
|
||||
let stderr = "";
|
||||
child.stderr.on("data", (d) => {
|
||||
stderr += String(d);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describeSettings, resolveAgentSettings } from "../src";
|
||||
import { compactionFromSettings, resolveModelFromSettings } from "../src/pi/model";
|
||||
import { describeSettings, resolveAgentSettings } from "../src/index.ts";
|
||||
import { compactionFromSettings, resolveModelFromSettings } from "../src/pi/model.ts";
|
||||
|
||||
describe("AgentSettings → pi-ai", () => {
|
||||
it("anthropic:baseUrl 去掉 /v1,上下文预算即 contextWindow,apiKey 只在 resolve 时给出", async () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"extends": "../../config/tsconfig.base.json",
|
||||
"include": ["src", "test"]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "@umt/contracts",
|
||||
"version": "0.0.0",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"tasks": {
|
||||
"test": "deno run -A npm:vitest run",
|
||||
"typecheck": "deno run -A npm:typescript/tsc --noEmit -p tsconfig.json"
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,8 @@
|
||||
{
|
||||
"name": "@umt/contracts",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc -p tsconfig.json",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"zod": "^4.3.6"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common";
|
||||
import { EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common.ts";
|
||||
|
||||
// 人工/AI 域:Agent 运行、证据/计划产物、待处理事项、审批、持续授权(REQ §10、§11.3、§11.4)
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { z } from "zod";
|
||||
import * as agent from "./agent";
|
||||
import * as assets from "./assets";
|
||||
import { CapabilityDescriptor, KnownCapabilityId } from "./capability";
|
||||
import { type ApiScope, CursorQuery, cursorPage, Id, IdParam } from "./common";
|
||||
import * as content from "./content";
|
||||
import * as execution from "./execution";
|
||||
import * as identity from "./identity";
|
||||
import * as instances from "./instances";
|
||||
import * as ops from "./ops";
|
||||
import * as organization from "./organization";
|
||||
import * as policy from "./policy";
|
||||
import { GlobalSettings, GlobalSettingsUpdate } from "./settings";
|
||||
import * as sources from "./sources";
|
||||
import * as agent from "./agent.ts";
|
||||
import * as assets from "./assets.ts";
|
||||
import { CapabilityDescriptor, KnownCapabilityId } from "./capability.ts";
|
||||
import { type ApiScope, CursorQuery, cursorPage, Id, IdParam } from "./common.ts";
|
||||
import * as content from "./content.ts";
|
||||
import * as execution from "./execution.ts";
|
||||
import * as identity from "./identity.ts";
|
||||
import * as instances from "./instances.ts";
|
||||
import * as ops from "./ops.ts";
|
||||
import * as organization from "./organization.ts";
|
||||
import * as policy from "./policy.ts";
|
||||
import { GlobalSettings, GlobalSettingsUpdate } from "./settings.ts";
|
||||
import * as sources from "./sources.ts";
|
||||
|
||||
// 所有 REST 端点的路径常量与请求/响应 schema 汇总。
|
||||
// path 相对 API_PREFIX,参数用 OpenAPI 风格 `{id}`(server 的 createRoute 直接使用);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common";
|
||||
import { Segment } from "./content";
|
||||
import { EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common.ts";
|
||||
import { Segment } from "./content.ts";
|
||||
|
||||
// 文件域:资产、资产-内容单元覆盖、资产位置、路径绑定(REQ §7.1、§8.2、§12.2)
|
||||
// 资产与位置分离;path_binding 一旦建立不因元数据刷新改变,只有显式整理可替换(旧绑定标 superseded)。
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { z } from "zod";
|
||||
import { MediaAsset } from "./assets";
|
||||
import type { KnownCapabilityId } from "./capability";
|
||||
import { Id, JsonObject, NonNegInt } from "./common";
|
||||
import { MediaEntity, MediaKind } from "./content";
|
||||
import { AcquisitionPlan, DownloadTask, Task, TaskStatus } from "./execution";
|
||||
import { ExternalEntityType, ExternalIdentity } from "./identity";
|
||||
import { ServerMapping } from "./ops";
|
||||
import { OrganizationAction, OrganizationRecord } from "./organization";
|
||||
import { AcquisitionSlot, PolicyRevision } from "./policy";
|
||||
import { SourceRelease } from "./sources";
|
||||
import { MediaAsset } from "./assets.ts";
|
||||
import type { KnownCapabilityId } from "./capability.ts";
|
||||
import { Id, JsonObject, NonNegInt } from "./common.ts";
|
||||
import { MediaEntity, MediaKind } from "./content.ts";
|
||||
import { AcquisitionPlan, DownloadTask, Task, TaskStatus } from "./execution.ts";
|
||||
import { ExternalEntityType, ExternalIdentity } from "./identity.ts";
|
||||
import { ServerMapping } from "./ops.ts";
|
||||
import { OrganizationAction, OrganizationRecord } from "./organization.ts";
|
||||
import { AcquisitionSlot, PolicyRevision } from "./policy.ts";
|
||||
import { SourceRelease } from "./sources.ts";
|
||||
|
||||
// 首批能力的输入/输出 schema;名字与 CAPABILITY_CATALOG 中的 inputSchema/outputSchema 一致。
|
||||
// 写能力的输入只接受计划/对象 ID,不接受模型自拟的幂等键或任意路径。
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { ApiScope } from "./common";
|
||||
import { ApiScope } from "./common.ts";
|
||||
|
||||
/**
|
||||
* 能力调用上下文(REQ §10.3)。产品自有接口,不是 Pi SDK 原生 API。
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { DateOnly, EntityBase, Id, JsonObject, SERVER_MANAGED, Timestamp } from "./common";
|
||||
import { DateOnly, EntityBase, Id, JsonObject, SERVER_MANAGED, Timestamp } from "./common.ts";
|
||||
|
||||
// 内容域:本地作品、内容单元、别名(REQ §3.1、§5.1、§5.4、§7.5)
|
||||
// 本地 UUID 是主身份;季/集编号、外部 ID 都可修订,不是唯一身份。
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { z } from "zod";
|
||||
import { AgentRunStatus, DecisionKind, DecisionStatus, Severity } from "./agent";
|
||||
import { Id, NonNegInt, Timestamp } from "./common";
|
||||
import { DownloadStatus, PauseReason, TaskKind, TaskStatus } from "./execution";
|
||||
import { OrganizationStatus } from "./organization";
|
||||
import { FeedHealth } from "./sources";
|
||||
import { AgentRunStatus, DecisionKind, DecisionStatus, Severity } from "./agent.ts";
|
||||
import { Id, NonNegInt, Timestamp } from "./common.ts";
|
||||
import { DownloadStatus, PauseReason, TaskKind, TaskStatus } from "./execution.ts";
|
||||
import { OrganizationStatus } from "./organization.ts";
|
||||
import { FeedHealth } from "./sources.ts";
|
||||
|
||||
/** SSE 事件信封:seq 在进程内单调递增,客户端断线后用 ?after=<seq> 补读 */
|
||||
export const EventEnvelope = z.object({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common";
|
||||
import { AcquisitionPriority } from "./policy";
|
||||
import { EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common.ts";
|
||||
import { AcquisitionPriority } from "./policy.ts";
|
||||
|
||||
// 执行域:业务任务、下载计划、下载任务、操作账本(REQ §8.4、§11;ADR-002)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { ActorType, EntityBase, Id, JsonObject, Timestamp } from "./common";
|
||||
import { ActorType, EntityBase, Id, JsonObject, Timestamp } from "./common.ts";
|
||||
|
||||
// 身份域:外部身份映射与修订(REQ §7.2)
|
||||
// provider + entityType + externalId 对 accepted 唯一;TMDB movie:123 与 tv:123 是两个身份。
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
export * from "./agent";
|
||||
export * from "./api";
|
||||
export * from "./assets";
|
||||
export * from "./capabilities-io";
|
||||
export * from "./capability";
|
||||
export * from "./common";
|
||||
export * from "./content";
|
||||
export * from "./events";
|
||||
export * from "./execution";
|
||||
export * from "./identity";
|
||||
export * from "./instances";
|
||||
export * from "./ops";
|
||||
export * from "./organization";
|
||||
export * from "./policy";
|
||||
export * from "./settings";
|
||||
export * from "./sources";
|
||||
export * from "./agent.ts";
|
||||
export * from "./api.ts";
|
||||
export * from "./assets.ts";
|
||||
export * from "./capabilities-io.ts";
|
||||
export * from "./capability.ts";
|
||||
export * from "./common.ts";
|
||||
export * from "./content.ts";
|
||||
export * from "./events.ts";
|
||||
export * from "./execution.ts";
|
||||
export * from "./identity.ts";
|
||||
export * from "./instances.ts";
|
||||
export * from "./ops.ts";
|
||||
export * from "./organization.ts";
|
||||
export * from "./policy.ts";
|
||||
export * from "./settings.ts";
|
||||
export * from "./sources.ts";
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { EntityBase, Id, JsonObject, SERVER_MANAGED, Timestamp } from "./common";
|
||||
import { EntityBase, Id, JsonObject, SERVER_MANAGED, Timestamp } from "./common.ts";
|
||||
|
||||
// 实例域:媒体库根、下载器实例、媒体服务器实例、路径映射(REQ §7.1、§8.4、§12.5)
|
||||
// 凭证只以 secretRef 暴露;创建/更新时的 credential 是只写明文,服务端加密为 secret 后丢弃。
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { ActorType, ApiScope, EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common";
|
||||
import { ActorType, ApiScope, EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common.ts";
|
||||
|
||||
// 运维域:校验运行、媒体服务器库存映射、API Key、审计、outbox、凭证(REQ §8.1、§7.4、§13.2)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { ActorType, EntityBase, Id, JsonObject, NonNegInt, Timestamp } from "./common";
|
||||
import { MediaKind } from "./content";
|
||||
import { ActorType, EntityBase, Id, JsonObject, NonNegInt, Timestamp } from "./common.ts";
|
||||
import { MediaKind } from "./content.ts";
|
||||
|
||||
// 整理域:整理记录(批次)+ 逐文件结果,以及对外开放的整理记录 API 合同(REQ §12.4)
|
||||
// 自动与手动整理产生同格式记录;读记录需 organize.read,发起整理需 organize.execute。
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { EntityBase, Id, JsonObject, SERVER_MANAGED, Timestamp } from "./common";
|
||||
import { EntityBase, Id, JsonObject, SERVER_MANAGED, Timestamp } from "./common.ts";
|
||||
|
||||
// 规则域:订阅、策略版本、收录 Slot、偏好标签与抑制记录(REQ §6)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { Id, Timestamp } from "./common";
|
||||
import { Id, Timestamp } from "./common.ts";
|
||||
|
||||
// 全局设置:存于 settings 表(key → jsonb)。每个顶层分组对应一个 settings.key。
|
||||
// schema 本身不带 .default()(zod 4 在 partial 里仍会套默认值,会让 PATCH 覆盖现值);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common";
|
||||
import { EntityBase, Id, JsonObject, NonNegInt, SERVER_MANAGED, Timestamp } from "./common.ts";
|
||||
|
||||
// 来源域:站点、站点账号、Feed、站点资源、观察(REQ §4)
|
||||
// 含 passkey 的 Feed URL 只以 urlSecretRef 保存,对外只给脱敏的 urlDisplay。
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { API_ERROR_STATUS, apiResponse, CapabilityId, CursorQuery, EventEnvelope, Id } from "../src";
|
||||
import { API_ERROR_STATUS, apiResponse, CapabilityId, CursorQuery, EventEnvelope, Id } from "../src/index.ts";
|
||||
|
||||
describe("contracts", () => {
|
||||
it("Id 只接受 uuid", () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { z } from "zod";
|
||||
import * as C from "../src";
|
||||
import * as C from "../src/index.ts";
|
||||
|
||||
// 与 packages/db/src/types.ts(从迁移反射生成)做文本级对照:
|
||||
// 1) 每张表的列 ⇔ 对应 Row schema 的字段(camelCase),只允许显式列出的差异;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
import * as C from "../src";
|
||||
import * as C from "../src/index.ts";
|
||||
|
||||
// 对 contracts 导出的每个 zod schema 做正反例 parse:
|
||||
// 正例由 sample() 按 schema 结构生成(字符串/数字按候选值逐个试到通过),个别 refine 由 OVERRIDES 修正;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"extends": "../../config/tsconfig.base.json",
|
||||
"include": ["src", "test"]
|
||||
}
|
||||
@@ -5,7 +5,7 @@ PostgreSQL 访问层:Kysely 客户端与连接池、表类型(`src/types.ts`)、
|
||||
## 规则
|
||||
|
||||
- **迁移是唯一事实来源**。所有 schema 变更只能新增迁移,已发布迁移不得修改。迁移用原生 DDL 书写(`src/migration-helpers.ts`:`entityTable()` 统一加 uuid 主键 `gen_random_uuid()`、`created_at/updated_at` 与 updated_at 触发器;`oneOf()` 生成状态 CHECK)。`migrations/` 内相对导入必须带 `.ts` 扩展名(Kysely 用原生 `import()` 加载)。
|
||||
- **`src/types.ts` 是生成物**:`pnpm db:migrate && pnpm --filter @umt/db gen:types`。CHECK 枚举自动变成字面量联合(如 `AcquisitionSlotStatus`)。`test/schema.test.ts` 会在隔离 schema 里重新反射并比对,漂移即失败;`packages/contracts/test/db-sync.test.ts` 再校验 contracts 的 Row schema 与枚举和这里一致。
|
||||
- **`src/types.ts` 是生成物**:`deno task db:migrate && deno task gen:types`。CHECK 枚举自动变成字面量联合(如 `AcquisitionSlotStatus`)。`test/schema.test.ts` 会在隔离 schema 里重新反射并比对,漂移即失败;`packages/contracts/test/db-sync.test.ts` 再校验 contracts 的 Row schema 与枚举和这里一致。
|
||||
- 状态列一律 `text + CHECK`,不用 PG enum(便于迁移加值)。JSONB 只放证据、规则参数、原文快照与演进字段;稳定查询字段用关系列。
|
||||
- 凭证只存 `secret_ref`(→ `secret.id`),明文不入库、不进日志。
|
||||
- `createDb()` 把 `int8` 解析为 `number`(超出 2^53 抛错)、`date` 保持 `YYYY-MM-DD` 字符串。写 jsonb 数组时须先 `JSON.stringify`(pg 会把 JS 数组当 PG 数组)。
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "@umt/db",
|
||||
"version": "0.0.0",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"tasks": {
|
||||
"test": "deno run -A npm:vitest run",
|
||||
"typecheck": "deno run -A npm:typescript/tsc --noEmit -p tsconfig.json",
|
||||
"migrate": "deno run -A --env-file=../../.env scripts/migrate.ts latest",
|
||||
"reset": "deno run -A --env-file=../../.env scripts/migrate.ts reset",
|
||||
"gen:types": "deno run -A --env-file=../../.env scripts/gen-types.ts"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,8 @@
|
||||
{
|
||||
"name": "@umt/db",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc -p tsconfig.json",
|
||||
"test": "vitest run",
|
||||
"migrate": "tsx --env-file-if-exists=../../.env scripts/migrate.ts latest",
|
||||
"reset": "tsx --env-file-if-exists=../../.env scripts/migrate.ts reset",
|
||||
"gen:types": "tsx --env-file-if-exists=../../.env scripts/gen-types.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"kysely": "^0.29.6",
|
||||
"pg": "^8.23.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/pg": "^8.23.1"
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { type Kysely, sql } from "kysely";
|
||||
|
||||
// 从已迁移的数据库反射出 src/types.ts:列类型 + CHECK (col in (...)) 枚举字面量联合。
|
||||
// 迁移是唯一事实来源;改表后运行 `pnpm --filter @umt/db gen:types`,测试会校验两者无漂移。
|
||||
// 迁移是唯一事实来源;改表后运行 `deno task gen:types`,测试会校验两者无漂移。
|
||||
|
||||
interface ColumnInfo {
|
||||
table_name: string;
|
||||
@@ -73,7 +73,7 @@ export async function generateTypesSource(db: Kysely<any>): Promise<string> {
|
||||
|
||||
const out: string[] = [
|
||||
"// 本文件由 scripts/gen-types.ts 从迁移后的数据库反射生成,请勿手改。",
|
||||
"// 改表:新增迁移 → pnpm db:migrate → pnpm --filter @umt/db gen:types。",
|
||||
"// 改表:新增迁移 → deno task db:migrate → deno task gen:types。",
|
||||
"",
|
||||
'import type { ColumnType, Generated, Insertable, Selectable, Updateable } from "kysely";',
|
||||
"",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// 用法:tsx scripts/gen-types.ts —— 对 DATABASE_URL 的当前 schema 反射并重写 src/types.ts
|
||||
// 用法:deno task gen:types —— 对 DATABASE_URL 的当前 schema 反射并重写 src/types.ts
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { createDb } from "../src";
|
||||
import { formatWithBiome, generateTypesSource, TYPES_FILE } from "./gen-types-lib";
|
||||
import { createDb } from "../src/index.ts";
|
||||
import { formatWithBiome, generateTypesSource, TYPES_FILE } from "./gen-types-lib.ts";
|
||||
|
||||
const db = createDb({ max: 1 });
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// 用法:tsx scripts/migrate.ts latest|reset
|
||||
import { createDb, migrateToLatest, resetSchema } from "../src";
|
||||
// 用法:deno task db:migrate / db:reset(= deno run -A --env-file=.env packages/db/scripts/migrate.ts latest|reset)
|
||||
import { createDb, migrateToLatest, resetSchema } from "../src/index.ts";
|
||||
|
||||
const cmd = process.argv[2] ?? "latest";
|
||||
const db = createDb({ max: 1 });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Kysely, PostgresDialect } from "kysely";
|
||||
import pg from "pg";
|
||||
import type { DB } from "./types";
|
||||
import type { DB } from "./types.ts";
|
||||
|
||||
// int8 → number(大小/序号都在 2^53 内;超出即报错而不是静默丢精度)
|
||||
pg.types.setTypeParser(pg.types.builtins.INT8, (v: string) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// 统一从本包取 Kysely 与 sql,避免各包各装一份 kysely
|
||||
export { type Kysely, sql, type Transaction } from "kysely";
|
||||
export { type CreateDbOptions, createDb } from "./client";
|
||||
export { createMigrator, MIGRATIONS_DIR, type MigratorOptions, migrateToLatest, resetSchema } from "./migrator";
|
||||
export type * from "./types";
|
||||
export { type CreateDbOptions, createDb } from "./client.ts";
|
||||
export { createMigrator, MIGRATIONS_DIR, type MigratorOptions, migrateToLatest, resetSchema } from "./migrator.ts";
|
||||
export type * from "./types.ts";
|
||||
@@ -1,5 +1,5 @@
|
||||
// 本文件由 scripts/gen-types.ts 从迁移后的数据库反射生成,请勿手改。
|
||||
// 改表:新增迁移 → pnpm db:migrate → pnpm --filter @umt/db gen:types。
|
||||
// 改表:新增迁移 → deno task db:migrate → deno task gen:types。
|
||||
|
||||
import type { ColumnType, Generated, Insertable, Selectable, Updateable } from "kysely";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { readdirSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { MIGRATIONS_DIR } from "../src";
|
||||
import { MIGRATIONS_DIR } from "../src/index.ts";
|
||||
|
||||
describe("migrations", () => {
|
||||
it("迁移文件按 NNNN_name.ts 命名且导出 up/down", async () => {
|
||||
|
||||
@@ -3,8 +3,8 @@ import { Kysely, PostgresDialect, sql } from "kysely";
|
||||
import { NO_MIGRATIONS } from "kysely/migration";
|
||||
import pg from "pg";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { formatWithBiome, generateTypesSource, TYPES_FILE } from "../scripts/gen-types-lib";
|
||||
import { createMigrator, type DB, migrateToLatest } from "../src";
|
||||
import { formatWithBiome, generateTypesSource, TYPES_FILE } from "../scripts/gen-types-lib.ts";
|
||||
import { createMigrator, type DB, migrateToLatest } from "../src/index.ts";
|
||||
|
||||
// 对真实 PG(默认开发库 55433)跑迁移往返;每次测试用独立 schema,互不干扰且不碰 public。
|
||||
// 无数据库环境可设 UMT_SKIP_DB_TESTS=1 跳过(CI 默认要求数据库可用)。
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
// 迁移文件由 Kysely FileMigrationProvider 用原生 import() 加载(Node 类型剥离,不做无扩展名解析),
|
||||
// 因此 migrations/ 内相对导入必须写 .ts 扩展名
|
||||
"allowImportingTsExtensions": true
|
||||
},
|
||||
"extends": "../../config/tsconfig.base.json",
|
||||
"include": ["src", "test", "scripts", "migrations"]
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
- 禁止 import 任何网络/文件/数据库库,也不读全局配置与时钟;时间(`now`)、设备号、文件清单、已存在目标等事实一律由调用方传入。
|
||||
- 不依赖 `@umt/contracts`:这里的类型是领域类型,W2 在 server/tasks 层映射到 zod 合同。
|
||||
- 唯一入口 `src/index.ts`(`export *` 各模块)。测试:`pnpm --filter @umt/domain test`。
|
||||
- 唯一入口 `src/index.ts`(`export *` 各模块)。测试:`cd packages/domain && deno task test`。
|
||||
|
||||
## 模块地图
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "@umt/domain",
|
||||
"version": "0.0.0",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"tasks": {
|
||||
"test": "deno run -A npm:vitest run",
|
||||
"typecheck": "deno run -A npm:typescript/tsc --noEmit -p tsconfig.json"
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
{
|
||||
"name": "@umt/domain",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc -p tsconfig.json",
|
||||
"test": "vitest run"
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ export {
|
||||
type BudgetUsage,
|
||||
type BudgetViolation,
|
||||
checkBudget,
|
||||
} from "./budget";
|
||||
} from "./budget.ts";
|
||||
export {
|
||||
type CacheVolumeDecision,
|
||||
type CacheVolumeInput,
|
||||
@@ -14,8 +14,8 @@ export {
|
||||
type Reservation,
|
||||
type ThresholdConfig,
|
||||
type VolumeSnapshot,
|
||||
} from "./disk";
|
||||
export { type AcquisitionMode, determineMode, type ModeDecision, type ModeInput } from "./mode";
|
||||
} from "./disk.ts";
|
||||
export { type AcquisitionMode, determineMode, type ModeDecision, type ModeInput } from "./mode.ts";
|
||||
export {
|
||||
DEFAULT_PRIORITY_ORDER,
|
||||
type PriorityClass,
|
||||
@@ -23,4 +23,4 @@ export {
|
||||
type QueueItem,
|
||||
sortByPriority,
|
||||
validatePriorityOrder,
|
||||
} from "./priority";
|
||||
} from "./priority.ts";
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AcquisitionMode } from "./mode";
|
||||
import type { AcquisitionMode } from "./mode.ts";
|
||||
|
||||
/** 默认:用户明确立即处理 > 追更补缺 > 新作品 > 已有版本升级(REQ §6.8) */
|
||||
export type PriorityClass = "immediate" | "catch_up" | "new_title" | "upgrade";
|
||||
|
||||
@@ -11,6 +11,6 @@ export {
|
||||
type TitleMatch,
|
||||
type TypeMatch,
|
||||
type YearMatch,
|
||||
} from "./match";
|
||||
export { normalizeTitle, stripSeasonSuffix } from "./normalize";
|
||||
export { TRAD_TO_SIMP, toSimplified } from "./zh-map";
|
||||
} from "./match.ts";
|
||||
export { normalizeTitle, stripSeasonSuffix } from "./normalize.ts";
|
||||
export { TRAD_TO_SIMP, toSimplified } from "./zh-map.ts";
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Confidence, ParsedRelease } from "../release-parser/types";
|
||||
import { normalizeTitle } from "./normalize";
|
||||
import type { Confidence, ParsedRelease } from "../release-parser/types.ts";
|
||||
import { normalizeTitle } from "./normalize.ts";
|
||||
|
||||
export interface IdentityCandidate {
|
||||
/** tmdb / local(本地别名召回)/ 其他提供方 */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CN_NUM } from "../release-parser/cn-number";
|
||||
import { toSimplified } from "./zh-map";
|
||||
import { CN_NUM } from "../release-parser/cn-number.ts";
|
||||
import { toSimplified } from "./zh-map.ts";
|
||||
|
||||
const SEASON_SUFFIX = [
|
||||
new RegExp(`\\s*第\\s*${CN_NUM}\\s*[季部]\\s*$`, "u"),
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// @umt/domain 公开入口:纯业务逻辑,无 IO。模块地图与不变量见 packages/domain/README.md
|
||||
export const PACKAGE_NAME = "@umt/domain";
|
||||
|
||||
export * from "./acquisition";
|
||||
export * from "./download-state";
|
||||
export * from "./identity";
|
||||
export * from "./organize";
|
||||
export * from "./path";
|
||||
export * from "./release-parser";
|
||||
export * from "./slot";
|
||||
export * from "./acquisition/index.ts";
|
||||
export * from "./download-state/index.ts";
|
||||
export * from "./identity/index.ts";
|
||||
export * from "./organize/index.ts";
|
||||
export * from "./path/index.ts";
|
||||
export * from "./release-parser/index.ts";
|
||||
export * from "./slot/index.ts";
|
||||
@@ -12,5 +12,5 @@ export {
|
||||
type Precondition,
|
||||
planOrganize,
|
||||
type SourceFile,
|
||||
} from "./plan";
|
||||
export { sidecarLanguageSuffix, sidecarStem } from "./sidecars";
|
||||
} from "./plan.ts";
|
||||
export { sidecarLanguageSuffix, sidecarStem } from "./sidecars.ts";
|
||||
@@ -1,9 +1,9 @@
|
||||
import { DEFAULT_TEMPLATES, type NamingTemplateSet, renderMediaFileName } from "../path/binding";
|
||||
import { buildNamingContext } from "../path/template";
|
||||
import { type ParseOptions, parseReleasePath } from "../release-parser";
|
||||
import { fileKindOf } from "../release-parser/parse";
|
||||
import type { ParsedRelease } from "../release-parser/types";
|
||||
import { basename, dirname, sidecarLanguageSuffix, sidecarStem, splitExt } from "./sidecars";
|
||||
import { DEFAULT_TEMPLATES, type NamingTemplateSet, renderMediaFileName } from "../path/binding.ts";
|
||||
import { buildNamingContext } from "../path/template.ts";
|
||||
import { type ParseOptions, parseReleasePath } from "../release-parser/index.ts";
|
||||
import { fileKindOf } from "../release-parser/parse.ts";
|
||||
import type { ParsedRelease } from "../release-parser/types.ts";
|
||||
import { basename, dirname, sidecarLanguageSuffix, sidecarStem, splitExt } from "./sidecars.ts";
|
||||
|
||||
export type OrganizeOperation = "copy" | "move" | "rename";
|
||||
export type OrganizeFileKind = "video" | "subtitle" | "audio" | "nfo" | "other";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { sanitizeFileName, sanitizeSegment } from "./sanitize";
|
||||
import { compileTemplate, type NamingContext, renderTemplate, type TemplateVar } from "./template";
|
||||
import { sanitizeFileName, sanitizeSegment } from "./sanitize.ts";
|
||||
import { compileTemplate, type NamingContext, renderTemplate, type TemplateVar } from "./template.ts";
|
||||
|
||||
export interface LibraryRoot {
|
||||
id: string;
|
||||
|
||||
@@ -10,10 +10,10 @@ export {
|
||||
resolveTargetDirectory,
|
||||
type TargetDirectoryDecision,
|
||||
validateTemplateSet,
|
||||
} from "./binding";
|
||||
export { detectPathConflicts, type ExistingPath, type PathConflict, type PlannedPath } from "./conflicts";
|
||||
export { type MapResult, type PathMapping, toDownloaderPath, toHostPath, validatePathMappings } from "./mapping";
|
||||
export { sanitizeFileName, sanitizeSegment, utf8Length } from "./sanitize";
|
||||
} from "./binding.ts";
|
||||
export { detectPathConflicts, type ExistingPath, type PathConflict, type PlannedPath } from "./conflicts.ts";
|
||||
export { type MapResult, type PathMapping, toDownloaderPath, toHostPath, validatePathMappings } from "./mapping.ts";
|
||||
export { sanitizeFileName, sanitizeSegment, utf8Length } from "./sanitize.ts";
|
||||
export {
|
||||
buildNamingContext,
|
||||
type CompiledTemplate,
|
||||
@@ -24,4 +24,4 @@ export {
|
||||
TEMPLATE_VARS,
|
||||
TemplateError,
|
||||
type TemplateVar,
|
||||
} from "./template";
|
||||
} from "./template.ts";
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ParsedRelease } from "../release-parser/types";
|
||||
import { sanitizeSegment } from "./sanitize";
|
||||
import type { ParsedRelease } from "../release-parser/types.ts";
|
||||
import { sanitizeSegment } from "./sanitize.ts";
|
||||
|
||||
/** 受限模板(白名单变量 + 可选片段),不用 Jinja/任意表达式 */
|
||||
export const TEMPLATE_VARS = [
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
export { cnToInt } from "./cn-number";
|
||||
export { evalEpisodeOffset, normalizeOffsetExpression, OffsetExpressionError } from "./offset";
|
||||
export { type CnMarkers, confidenceOf, fileKindOf, parseRelease, scanCnMarkers } from "./parse";
|
||||
export { mergeParsed, type PathSegments, parseReleasePath, splitReleasePath } from "./path";
|
||||
export { buildGroupRegex, RELEASE_GROUP_SEED } from "./release-groups";
|
||||
export * from "./types";
|
||||
export { cnToInt } from "./cn-number.ts";
|
||||
export { evalEpisodeOffset, normalizeOffsetExpression, OffsetExpressionError } from "./offset.ts";
|
||||
export { type CnMarkers, confidenceOf, fileKindOf, parseRelease, scanCnMarkers } from "./parse.ts";
|
||||
export { mergeParsed, type PathSegments, parseReleasePath, splitReleasePath } from "./path.ts";
|
||||
export { buildGroupRegex, RELEASE_GROUP_SEED } from "./release-groups.ts";
|
||||
export * from "./types.ts";
|
||||
|
||||
import type { EpisodeRange } from "./types";
|
||||
import type { EpisodeRange } from "./types.ts";
|
||||
/** 展开集号区间 */
|
||||
export function expandEpisodes(r: EpisodeRange | undefined): number[] {
|
||||
if (!r) return [];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CN_NUM, cnToInt } from "./cn-number";
|
||||
import { evalEpisodeOffset } from "./offset";
|
||||
import { buildGroupRegex, defaultGroupRegex } from "./release-groups";
|
||||
import { CN_NUM, cnToInt } from "./cn-number.ts";
|
||||
import { evalEpisodeOffset } from "./offset.ts";
|
||||
import { buildGroupRegex, defaultGroupRegex } from "./release-groups.ts";
|
||||
import {
|
||||
type Confidence,
|
||||
type ContentType,
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
type Resolution,
|
||||
type Segment,
|
||||
type VideoCodec,
|
||||
} from "./types";
|
||||
} from "./types.ts";
|
||||
|
||||
// ---------------------------------------------------------------- 扩展名
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { confidenceOf, parseRelease } from "./parse";
|
||||
import type { Confidence, PackHint, ParsedRelease, ParseOptions } from "./types";
|
||||
import { confidenceOf, parseRelease } from "./parse.ts";
|
||||
import type { Confidence, PackHint, ParsedRelease, ParseOptions } from "./types.ts";
|
||||
|
||||
export interface PathSegments {
|
||||
file: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Cut } from "../release-parser/types";
|
||||
import type { SlotGroupSpec } from "./types";
|
||||
import type { Cut } from "../release-parser/types.ts";
|
||||
import type { SlotGroupSpec } from "./types.ts";
|
||||
|
||||
export interface MovieAssetFact {
|
||||
assetId: string;
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import type { ParsedRelease, ReleaseSource, Resolution } from "../release-parser/types";
|
||||
import type { HardField, QualityFacts, QualityTier, SlotEvaluation, SlotSpec, UnknownPolicy, Violation } from "./types";
|
||||
import type { ParsedRelease, ReleaseSource, Resolution } from "../release-parser/types.ts";
|
||||
import type {
|
||||
HardField,
|
||||
QualityFacts,
|
||||
QualityTier,
|
||||
SlotEvaluation,
|
||||
SlotSpec,
|
||||
UnknownPolicy,
|
||||
Violation,
|
||||
} from "./types.ts";
|
||||
|
||||
export const DEFAULT_SOURCE_TIERS: Readonly<Record<ReleaseSource, number>> = {
|
||||
REMUX: 3,
|
||||
|
||||
@@ -5,7 +5,7 @@ export {
|
||||
type UnitAssetFact,
|
||||
type UnitCompletion,
|
||||
unitCompletion,
|
||||
} from "./completion";
|
||||
} from "./completion.ts";
|
||||
export {
|
||||
checkHardConditions,
|
||||
compareRank,
|
||||
@@ -16,7 +16,7 @@ export {
|
||||
RESOLUTION_RANK,
|
||||
rankForSlot,
|
||||
softRank,
|
||||
} from "./evaluate";
|
||||
} from "./evaluate.ts";
|
||||
export {
|
||||
canTransition,
|
||||
type SlotEvent,
|
||||
@@ -24,5 +24,5 @@ export {
|
||||
type SlotStatus,
|
||||
SlotTransitionError,
|
||||
transition,
|
||||
} from "./state";
|
||||
export * from "./types";
|
||||
} from "./state.ts";
|
||||
export * from "./types.ts";
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
ReleaseSource,
|
||||
Resolution,
|
||||
VideoCodec,
|
||||
} from "../release-parser/types";
|
||||
} from "../release-parser/types.ts";
|
||||
|
||||
/** 可判定的硬条件字段 */
|
||||
export type HardField = "resolution" | "source" | "size" | "subtitles" | "cut" | "group" | "contentType";
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
priorityOf,
|
||||
sortByPriority,
|
||||
validatePriorityOrder,
|
||||
} from "../src";
|
||||
} from "../src/index.ts";
|
||||
|
||||
const GiB = 1024 ** 3;
|
||||
const base: ModeInput = {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
isDownloadComplete,
|
||||
mapQbState,
|
||||
type ProgressSample,
|
||||
} from "../src";
|
||||
} from "../src/index.ts";
|
||||
|
||||
const ctx = { pausedByThreshold: false };
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
stripSeasonSuffix,
|
||||
TRAD_TO_SIMP,
|
||||
toSimplified,
|
||||
} from "../src";
|
||||
} from "../src/index.ts";
|
||||
|
||||
const movie = (over: Partial<IdentityCandidate> = {}): IdentityCandidate => ({
|
||||
provider: "tmdb",
|
||||
|
||||
Loaded 100 of 226 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user