@dtoolkit/core 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/ivncmp/dtoolkit/main/logo.png" alt="dtoolkit" />
3
+ </p>
4
+
5
+ <h1 align="center">@dtoolkit/core</h1>
6
+ <p align="center">Shared types and schemas for the dtoolkit ecosystem</p>
7
+
8
+ <p align="center">
9
+ <a href="https://www.npmjs.com/package/@dtoolkit/core"><img src="https://img.shields.io/npm/v/@dtoolkit/core.svg" alt="npm"></a>
10
+ <a href="../../LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"></a>
11
+ </p>
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @dtoolkit/core
17
+ ```
18
+
19
+ ## What's inside
20
+
21
+ ### Adapter types
22
+
23
+ The universal adapter contract used by all `@dtoolkit/adapter-*` packages:
24
+
25
+ | Export | Description |
26
+ | --- | --- |
27
+ | `Adapter` | Interface: `{ provider: string; execute(request): Promise<AdapterResult> }` |
28
+ | `AdapterRequest` | Request shape: prompt, model, maxTurns, sessionId, options |
29
+ | `AdapterResult` | Result shape: text, sessionId, costUsd, durationMs, usage, model, raw |
30
+ | `AdapterUsage` | Token counts: inputTokens, outputTokens, totalTokens |
31
+
32
+ ```ts
33
+ import type { Adapter, AdapterRequest, AdapterResult, AdapterUsage } from "@dtoolkit/core";
34
+ ```
35
+
36
+ ### Data types and schemas
37
+
38
+ | Export | Description |
39
+ | --- | --- |
40
+ | `Entity` | Entity type, PARA category, and Zod schema |
41
+ | `Fact` | Fact type with tier config and `computeTier()` |
42
+ | `ContextBlock` | Context injection block schema |
43
+ | `HistoryEntry` | Prompt history entry type |
44
+ | `TemplateDefinition` | YAML prompt template types |
45
+
46
+ ```ts
47
+ import { EntitySchema, computeTier, Tier } from "@dtoolkit/core";
48
+
49
+ const entity = EntitySchema.parse(data);
50
+
51
+ const tier = computeTier(fact, { hotDays: 7, hotMinAccess: 10, warmDays: 30 });
52
+ // Tier.HOT | Tier.WARM | Tier.COLD
53
+ ```
54
+
55
+ ## License
56
+
57
+ [MIT](../../LICENSE)
@@ -0,0 +1,36 @@
1
+ export interface AdapterRequest {
2
+ prompt: string;
3
+ systemPrompt?: string;
4
+ model?: string;
5
+ maxTurns?: number;
6
+ stdinContent?: string;
7
+ sessionId?: string;
8
+ continueSession?: boolean;
9
+ options?: Record<string, unknown>;
10
+ }
11
+ export interface AdapterUsage {
12
+ inputTokens: number;
13
+ outputTokens: number;
14
+ totalTokens: number;
15
+ }
16
+ export interface AdapterResult {
17
+ text: string;
18
+ sessionId?: string;
19
+ costUsd?: number;
20
+ durationMs: number;
21
+ isError: boolean;
22
+ usage?: AdapterUsage;
23
+ model?: string;
24
+ raw?: unknown;
25
+ }
26
+ export interface AdapterStreamEvent {
27
+ type: 'text' | 'result';
28
+ text?: string;
29
+ result?: AdapterResult;
30
+ }
31
+ export interface Adapter {
32
+ readonly provider: string;
33
+ execute(request: AdapterRequest): Promise<AdapterResult>;
34
+ stream(request: AdapterRequest): AsyncGenerator<AdapterStreamEvent>;
35
+ }
36
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACzD,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC;CACrE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export type { Adapter, AdapterRequest, AdapterResult, AdapterStreamEvent, AdapterUsage, } from "./adapter.js";
2
+ export { LineBuffer } from "./line-buffer.js";
1
3
  export { EntityType, ParaCategory, EntitySchema, type Entity, } from "./entity.js";
2
4
  export { Tier, FactSchema, type Fact, type TierConfig, computeTier, } from "./fact.js";
3
5
  export { ContextBlockSchema, type ContextBlock } from "./context.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,KAAK,MAAM,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,IAAI,EACJ,UAAU,EACV,KAAK,IAAI,EACT,KAAK,UAAU,EACf,WAAW,GACZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAErE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE9D,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,OAAO,EACP,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,KAAK,MAAM,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,IAAI,EACJ,UAAU,EACV,KAAK,IAAI,EACT,KAAK,UAAU,EACf,WAAW,GACZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAErE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE9D,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { LineBuffer } from "./line-buffer.js";
1
2
  export { EntityType, ParaCategory, EntitySchema, } from "./entity.js";
2
3
  export { Tier, FactSchema, computeTier, } from "./fact.js";
3
4
  export { ContextBlockSchema } from "./context.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,YAAY,GAEb,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,IAAI,EACJ,UAAU,EAGV,WAAW,GACZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,kBAAkB,EAAqB,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,UAAU,EACV,YAAY,EACZ,YAAY,GAEb,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,IAAI,EACJ,UAAU,EAGV,WAAW,GACZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,kBAAkB,EAAqB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare class LineBuffer {
2
+ private buffer;
3
+ push(chunk: string): string[];
4
+ flush(): string | undefined;
5
+ }
6
+ //# sourceMappingURL=line-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line-buffer.d.ts","sourceRoot":"","sources":["../src/line-buffer.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAM;IAEpB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAO7B,KAAK,IAAI,MAAM,GAAG,SAAS;CAK5B"}
@@ -0,0 +1,15 @@
1
+ export class LineBuffer {
2
+ buffer = '';
3
+ push(chunk) {
4
+ this.buffer += chunk;
5
+ const lines = this.buffer.split('\n');
6
+ this.buffer = lines.pop() ?? '';
7
+ return lines.filter((l) => l.trim());
8
+ }
9
+ flush() {
10
+ const remaining = this.buffer.trim();
11
+ this.buffer = '';
12
+ return remaining || undefined;
13
+ }
14
+ }
15
+ //# sourceMappingURL=line-buffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line-buffer.js","sourceRoot":"","sources":["../src/line-buffer.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IACb,MAAM,GAAG,EAAE,CAAC;IAEpB,IAAI,CAAC,KAAa;QAChB,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC;QACrB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,KAAK;QACH,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,OAAO,SAAS,IAAI,SAAS,CAAC;IAChC,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtoolkit/core",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Shared types for dtoolkit (ContextBlock, Fact, Entity, Tier, hooks API)",
5
5
  "type": "module",
6
6
  "license": "MIT",