@reinsjs/core 0.6.0 → 0.8.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.
@@ -1,4 +1,4 @@
1
- import { B as BlobStore, E as EventLog, a as Event, M as MemoryStore, r as RunLease, f as LoweringCapabilities, o as CoreEventDraft, U as LoweringOutcome, a5 as ToRequestInput, L as Lowering, e as ModelRef, k as LoweredRequest, V as LoweringStreamContext, c as EventDraft } from '../types-BOSGqMVX.js';
1
+ import { B as BlobStore, b as EventLog, E as Event, M as MemoryStore, r as RunLease, f as LoweringCapabilities, o as CoreEventDraft, U as LoweringOutcome, a5 as ToRequestInput, L as Lowering, e as ModelRef, k as LoweredRequest, V as LoweringStreamContext, c as EventDraft } from '../types-DkOLu2fW.js';
2
2
 
3
3
  /**
4
4
  * 一致性套件对测试框架的最小要求:只要 describe / it 两个函数。
@@ -108,6 +108,11 @@ interface ToolCallPayload {
108
108
  name: string;
109
109
  /** 模型给的原始入参(已解析为 JSON 值);校验在工具执行前做,事件里存原样 */
110
110
  args: unknown;
111
+ /**
112
+ * 降级层附带的读侧记录,**不进模型上下文**。目前只有 `argumentsUnwrapped: true`:模型把整个入参二次编码成了
113
+ * JSON 文本,降级层多解了一层(core/lowering/tool-arguments.ts)。可选字段,不升版本。
114
+ */
115
+ meta?: Record<string, unknown>;
111
116
  }
112
117
  interface ToolResultPayload {
113
118
  toolCallId: string;
@@ -389,121 +394,6 @@ declare function createEvent<T extends string, P>(registry: EventSchemaRegistry,
389
394
  /** 内置事件的强类型版本:type 与 payload 联动校验。 */
390
395
  declare function createCoreEvent<T extends CoreEventType>(registry: EventSchemaRegistry, input: CreateEventInput<T, CoreEventPayloads[T]>): CoreEventOf<T>;
391
396
 
392
- /**
393
- * 存储接口(技术方案 §5)。四者相互独立,允许部分实现:
394
- * - 只有 EventLog 就能跑
395
- * - 缺 BlobStore → spill 模块自动关闭并告警
396
- * - 缺 MemoryStore → memory 工具不注册
397
- * - 缺 RunLease → run 登记只在进程内(多实例部署要它,见 D4)
398
- *
399
- * 每个接口的行为契约由 ../testing 下的一致性套件定义,第三方后端跑同一套件即可自证合规。
400
- */
401
-
402
- interface ReadOptions {
403
- /** 起始 seq,含;缺省从 1 */
404
- fromSeq?: number;
405
- /** 结束 seq,含;缺省到末尾 */
406
- toSeq?: number;
407
- }
408
- /**
409
- * 事件日志:只 append,永不 update / delete(宪法二)。
410
- *
411
- * seq 由调用方分配(通常是 runLoop),日志只校验:同一批必须同会话、seq 从当前末尾 +1 起连续。
412
- * 这样并发写入者会在 append 时收到 seq_conflict,而不是静默交错 —— 乐观并发控制就这么简单。
413
- */
414
- interface EventLog {
415
- /** 同会话原子:整批要么全部写入,要么一个都不写 */
416
- append(events: readonly Event[]): Promise<void>;
417
- /** 按 seq 升序流式读取;不存在的会话得到空流 */
418
- read(sessionId: string, opts?: ReadOptions): AsyncIterable<Event>;
419
- /** 最后 n 条,按 seq 升序;不够 n 条就返回全部 */
420
- tail(sessionId: string, n: number): Promise<Event[]>;
421
- /**
422
- * 从 fromSessionId 的 [1, atSeq] 分叉出新会话 toSessionId。
423
- * 事件原样复制(保留 id 与 seq,只换 sessionId),以维持 parentId / pinsKept 等会话内引用。
424
- * 目标会话必须为空;atSeq 超出范围报错。
425
- */
426
- fork(fromSessionId: string, atSeq: number, toSessionId: string): Promise<void>;
427
- }
428
- interface BlobMeta {
429
- mime: string;
430
- sessionId: string;
431
- /** 字节数 */
432
- size: number;
433
- /** Unix 毫秒 */
434
- createdAt: number;
435
- }
436
- /** 大对象:外溢的工具结果、附件、代码执行产物。字符串按 UTF-8 编码存储。 */
437
- interface BlobStore {
438
- put(bytes: Uint8Array | string, meta: {
439
- mime: string;
440
- sessionId: string;
441
- }): Promise<{
442
- id: string;
443
- }>;
444
- /** 不存在抛 StoreError("not_found") */
445
- get(id: string): Promise<{
446
- bytes: Uint8Array;
447
- meta: BlobMeta;
448
- }>;
449
- /** 可选:分段取回 [start, end),供模型分页读大结果;越界部分截断 */
450
- slice?(id: string, range: {
451
- start: number;
452
- end: number;
453
- }): Promise<Uint8Array>;
454
- }
455
- /**
456
- * 记忆后端:一个极简的文本 KV,键是路径。
457
- * 路径限定(必须在 /memories 下、禁止 ..)由 memory 工具层负责(B6),存储层只管存取。
458
- */
459
- interface MemoryStore {
460
- /** 所有以 prefix 开头的路径,按字典序 */
461
- list(prefix: string): Promise<string[]>;
462
- /** 不存在返回 null */
463
- read(path: string): Promise<string | null>;
464
- /** 覆盖写 */
465
- write(path: string, content: string): Promise<void>;
466
- /** 幂等:不存在也不报错 */
467
- delete(path: string): Promise<void>;
468
- }
469
- /**
470
- * 技能载体(技术方案 §9.9,S1):MemoryStore 的只读子集。任何 MemoryStore(内存 / sqlite / pg)天然满足,
471
- * 数据库载体零新代码;文件系统载体 `fsSkillSource(dir)` 在 `@reinsjs/brain/node`。刻意不新造接口——"存哪"由宿主定。
472
- */
473
- type SkillSource = Pick<MemoryStore, "list" | "read">;
474
- /**
475
- * run 租约(D4,2026-09-14):多实例部署下"同一会话同时只允许一个 run"的跨进程登记表。
476
- *
477
- * 语义是**带过期时间的独占锁**:`acquire` 在无人持有、持有者已过期、或持有者就是自己时成功;
478
- * 持有者每隔一段时间 `renew` 续期,进程崩了不续期,到期后别的实例就能接手;`release` 只删自己持有的。
479
- * 过期判定用**存储层自己的时钟**(数据库时间),不用各实例本机时钟——租约的意义是各实例对"谁持有"达成一致,
480
- * 判定时钟必须唯一。三个方法都不抛"冲突"类错误,用返回值说话;存储不可用时照常抛。
481
- *
482
- * 心跳、丢租约中止、失败告警这些行为放在 `@reinsjs/server` 的 `leasedRunRegistry` 一份,store 只做三条语句。
483
- * 单进程部署不需要它(进程内登记表已够),`memoryStore()` 刻意不带;`InMemoryRunLease` 是参考实现与测试用。
484
- */
485
- interface RunLease {
486
- /**
487
- * 为会话占租约 ttlMs 毫秒。无人持有、持有者已过期、或持有者就是 owner(幂等,等于续期)→ true;
488
- * 别人仍持有且未过期 → false。
489
- */
490
- acquire(sessionId: string, owner: string, ttlMs: number): Promise<boolean>;
491
- /** 续期:owner 仍持有且未过期 → true 并延长到 now + ttlMs;已过期、被别人接手、或从未持有 → false */
492
- renew(sessionId: string, owner: string, ttlMs: number): Promise<boolean>;
493
- /** 释放:只删 owner 自己持有的那条;不是自己的、或不存在,静默返回 */
494
- release(sessionId: string, owner: string): Promise<void>;
495
- }
496
- /**
497
- * 一套存储:只有 log 是必需的(§5 允许部分实现),`createAgent({ store })` 接收的就是它。
498
- * 带 `runLease` 时 `createAgent` 自动把 handler 的 run 登记表换成跨进程的租约登记(D4)。
499
- */
500
- interface Stores {
501
- log: EventLog;
502
- blobs?: BlobStore;
503
- memory?: MemoryStore;
504
- runLease?: RunLease;
505
- }
506
-
507
397
  /**
508
398
  * 降级层接口(技术方案 §11;宪法二:角色只是翻译)。
509
399
  *
@@ -632,4 +522,119 @@ interface Lowering<TPayload = unknown> {
632
522
  stream(req: LoweredRequest<TPayload>, ctx?: LoweringStreamContext): AsyncGenerator<EventDraft, LoweringOutcome>;
633
523
  }
634
524
 
635
- export { type RunResumedPayload as $, type ApprovalRequestPayload as A, type BlobStore as B, type ContentPart as C, type CoreEventType as D, type EventLog as E, type CreateEventInput as F, DEFAULT_TRUST as G, type EventBase as H, type EventSchema as I, type ExtEvent as J, type HandoffPayload as K, type Lowering as L, type MemoryStore as M, type ImagePart as N, type LandingSpec as O, type LossKind as P, type LossMatrix as Q, type ReadOptions as R, type Stores as S, type TokenUsage as T, type LoweringOutcome as U, type LoweringStreamContext as V, type MemoryOpPayload as W, type ModelTextPayload as X, type ModelThinkingPayload as Y, type Provenance as Z, type RunPausedPayload as _, type Event as a, SchemaError as a0, type SchemaErrorCode as a1, type SkillSource as a2, type SystemNotePayload as a3, type TextPart as a4, type ToRequestInput as a5, type ToolReferencePart as a6, type ToolsBoundPayload as a7, type Upcaster as a8, type UserMessagePayload as a9, contextOverheadOf as aa, contextTokensOf as ab, createCoreEvent as ac, createCoreRegistry as ad, createEvent as ae, lossesOf as af, renderToolReference as ag, EventSchemaRegistry as b, type EventDraft as c, type Trust as d, type ModelRef as e, type LoweringCapabilities as f, type CoreEventOf as g, type ToolResultPayload as h, type LoweringDelta as i, type LandingRecord as j, type LoweredRequest as k, type ErrorPayload as l, type ToolCallPayload as m, type ToolSpec as n, type CoreEventDraft as o, type BudgetUsagePayload as p, type BlobMeta as q, type RunLease as r, type Actor as s, type AnyEvent as t, type ApprovalDecisionPayload as u, type BoundModel as v, CORE_SCHEMAS as w, type CompactionPayload as x, type CoreEvent as y, type CoreEventPayloads as z };
525
+ /**
526
+ * 存储接口(技术方案 §5)。四者相互独立,允许部分实现:
527
+ * - 只有 EventLog 就能跑
528
+ * - 缺 BlobStore → spill 模块自动关闭并告警
529
+ * - 缺 MemoryStore → memory 工具不注册
530
+ * - 缺 RunLease → run 登记只在进程内(多实例部署要它,见 D4)
531
+ *
532
+ * 每个接口的行为契约由 ../testing 下的一致性套件定义,第三方后端跑同一套件即可自证合规。
533
+ */
534
+
535
+ interface ReadOptions {
536
+ /** 起始 seq,含;缺省从 1 */
537
+ fromSeq?: number;
538
+ /** 结束 seq,含;缺省到末尾 */
539
+ toSeq?: number;
540
+ }
541
+ /**
542
+ * 事件日志:只 append,永不 update / delete(宪法二)。
543
+ *
544
+ * seq 由调用方分配(通常是 runLoop),日志只校验:同一批必须同会话、seq 从当前末尾 +1 起连续。
545
+ * 这样并发写入者会在 append 时收到 seq_conflict,而不是静默交错 —— 乐观并发控制就这么简单。
546
+ */
547
+ interface EventLog {
548
+ /** 同会话原子:整批要么全部写入,要么一个都不写 */
549
+ append(events: readonly Event[]): Promise<void>;
550
+ /** 按 seq 升序流式读取;不存在的会话得到空流 */
551
+ read(sessionId: string, opts?: ReadOptions): AsyncIterable<Event>;
552
+ /** 最后 n 条,按 seq 升序;不够 n 条就返回全部 */
553
+ tail(sessionId: string, n: number): Promise<Event[]>;
554
+ /**
555
+ * 从 fromSessionId 的 [1, atSeq] 分叉出新会话 toSessionId。
556
+ * 事件原样复制(保留 id 与 seq,只换 sessionId),以维持 parentId / pinsKept 等会话内引用。
557
+ * 目标会话必须为空;atSeq 超出范围报错。
558
+ */
559
+ fork(fromSessionId: string, atSeq: number, toSessionId: string): Promise<void>;
560
+ }
561
+ interface BlobMeta {
562
+ mime: string;
563
+ sessionId: string;
564
+ /** 字节数 */
565
+ size: number;
566
+ /** Unix 毫秒 */
567
+ createdAt: number;
568
+ }
569
+ /** 大对象:外溢的工具结果、附件、代码执行产物。字符串按 UTF-8 编码存储。 */
570
+ interface BlobStore {
571
+ put(bytes: Uint8Array | string, meta: {
572
+ mime: string;
573
+ sessionId: string;
574
+ }): Promise<{
575
+ id: string;
576
+ }>;
577
+ /** 不存在抛 StoreError("not_found") */
578
+ get(id: string): Promise<{
579
+ bytes: Uint8Array;
580
+ meta: BlobMeta;
581
+ }>;
582
+ /** 可选:分段取回 [start, end),供模型分页读大结果;越界部分截断 */
583
+ slice?(id: string, range: {
584
+ start: number;
585
+ end: number;
586
+ }): Promise<Uint8Array>;
587
+ }
588
+ /**
589
+ * 记忆后端:一个极简的文本 KV,键是路径。
590
+ * 路径限定(必须在 /memories 下、禁止 ..)由 memory 工具层负责(B6),存储层只管存取。
591
+ */
592
+ interface MemoryStore {
593
+ /** 所有以 prefix 开头的路径,按字典序 */
594
+ list(prefix: string): Promise<string[]>;
595
+ /** 不存在返回 null */
596
+ read(path: string): Promise<string | null>;
597
+ /** 覆盖写 */
598
+ write(path: string, content: string): Promise<void>;
599
+ /** 幂等:不存在也不报错 */
600
+ delete(path: string): Promise<void>;
601
+ }
602
+ /**
603
+ * 技能载体(技术方案 §9.9,S1):MemoryStore 的只读子集。任何 MemoryStore(内存 / sqlite / pg)天然满足,
604
+ * 数据库载体零新代码;文件系统载体 `fsSkillSource(dir)` 在 `@reinsjs/brain/node`。刻意不新造接口——"存哪"由宿主定。
605
+ */
606
+ type SkillSource = Pick<MemoryStore, "list" | "read">;
607
+ /**
608
+ * run 租约(D4,2026-09-14):多实例部署下"同一会话同时只允许一个 run"的跨进程登记表。
609
+ *
610
+ * 语义是**带过期时间的独占锁**:`acquire` 在无人持有、持有者已过期、或持有者就是自己时成功;
611
+ * 持有者每隔一段时间 `renew` 续期,进程崩了不续期,到期后别的实例就能接手;`release` 只删自己持有的。
612
+ * 过期判定用**存储层自己的时钟**(数据库时间),不用各实例本机时钟——租约的意义是各实例对"谁持有"达成一致,
613
+ * 判定时钟必须唯一。三个方法都不抛"冲突"类错误,用返回值说话;存储不可用时照常抛。
614
+ *
615
+ * 心跳、丢租约中止、失败告警这些行为放在 `@reinsjs/server` 的 `leasedRunRegistry` 一份,store 只做三条语句。
616
+ * 单进程部署不需要它(进程内登记表已够),`memoryStore()` 刻意不带;`InMemoryRunLease` 是参考实现与测试用。
617
+ */
618
+ interface RunLease {
619
+ /**
620
+ * 为会话占租约 ttlMs 毫秒。无人持有、持有者已过期、或持有者就是 owner(幂等,等于续期)→ true;
621
+ * 别人仍持有且未过期 → false。
622
+ */
623
+ acquire(sessionId: string, owner: string, ttlMs: number): Promise<boolean>;
624
+ /** 续期:owner 仍持有且未过期 → true 并延长到 now + ttlMs;已过期、被别人接手、或从未持有 → false */
625
+ renew(sessionId: string, owner: string, ttlMs: number): Promise<boolean>;
626
+ /** 释放:只删 owner 自己持有的那条;不是自己的、或不存在,静默返回 */
627
+ release(sessionId: string, owner: string): Promise<void>;
628
+ }
629
+ /**
630
+ * 一套存储:只有 log 是必需的(§5 允许部分实现),`createAgent({ store })` 接收的就是它。
631
+ * 带 `runLease` 时 `createAgent` 自动把 handler 的 run 登记表换成跨进程的租约登记(D4)。
632
+ */
633
+ interface Stores {
634
+ log: EventLog;
635
+ blobs?: BlobStore;
636
+ memory?: MemoryStore;
637
+ runLease?: RunLease;
638
+ }
639
+
640
+ export { type RunResumedPayload as $, type ApprovalRequestPayload as A, type BlobStore as B, type ContentPart as C, type CoreEventType as D, type Event as E, type CreateEventInput as F, DEFAULT_TRUST as G, type EventBase as H, type EventSchema as I, type ExtEvent as J, type HandoffPayload as K, type Lowering as L, type MemoryStore as M, type ImagePart as N, type LandingSpec as O, type LossKind as P, type LossMatrix as Q, type ReadOptions as R, type Stores as S, type TokenUsage as T, type LoweringOutcome as U, type LoweringStreamContext as V, type MemoryOpPayload as W, type ModelTextPayload as X, type ModelThinkingPayload as Y, type Provenance as Z, type RunPausedPayload as _, EventSchemaRegistry as a, SchemaError as a0, type SchemaErrorCode as a1, type SkillSource as a2, type SystemNotePayload as a3, type TextPart as a4, type ToRequestInput as a5, type ToolReferencePart as a6, type ToolsBoundPayload as a7, type Upcaster as a8, type UserMessagePayload as a9, contextOverheadOf as aa, contextTokensOf as ab, createCoreEvent as ac, createCoreRegistry as ad, createEvent as ae, lossesOf as af, renderToolReference as ag, type EventLog as b, type EventDraft as c, type Trust as d, type ModelRef as e, type LoweringCapabilities as f, type CoreEventOf as g, type ToolResultPayload as h, type LoweringDelta as i, type LandingRecord as j, type LoweredRequest as k, type ErrorPayload as l, type ToolCallPayload as m, type ToolSpec as n, type CoreEventDraft as o, type BudgetUsagePayload as p, type BlobMeta as q, type RunLease as r, type Actor as s, type AnyEvent as t, type ApprovalDecisionPayload as u, type BoundModel as v, CORE_SCHEMAS as w, type CompactionPayload as x, type CoreEvent as y, type CoreEventPayloads as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reinsjs/core",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "reins — core: append-only event timeline, projection, the copyable runLoop, serializable run state and the Socket seam. Zero dependencies, zero node:*",
5
5
  "keywords": [
6
6
  "agent",