@asaidimu/utils-workspace 6.1.0 → 6.2.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/README.md +157 -88
- package/index.d.mts +276 -204
- package/index.d.ts +276 -204
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -883,44 +883,45 @@ interface Preference {
|
|
|
883
883
|
/** UTC timestamp of when this preference was established or last updated. */
|
|
884
884
|
timestamp: Timestamp;
|
|
885
885
|
}
|
|
886
|
-
/**
|
|
887
|
-
type
|
|
888
|
-
/** Denotes raw, unstructured text. */
|
|
886
|
+
/** Supported payload for text-based context. */
|
|
887
|
+
type TextContextContent = {
|
|
889
888
|
kind: "text";
|
|
890
|
-
/** The text payload to inject. */
|
|
891
889
|
value: string;
|
|
892
|
-
}
|
|
893
|
-
|
|
890
|
+
};
|
|
891
|
+
/** Supported payload for structured JSON context. */
|
|
892
|
+
type JsonContextContent = {
|
|
894
893
|
kind: "json";
|
|
895
|
-
/** The JSON payload. */
|
|
896
894
|
value: unknown;
|
|
897
|
-
}
|
|
898
|
-
|
|
895
|
+
};
|
|
896
|
+
/** Supported payload for blob-based context. */
|
|
897
|
+
type BlobContextContent = {
|
|
899
898
|
kind: "blob";
|
|
900
|
-
/** The hash linking to the full blob record. */
|
|
901
899
|
sha256: SHA256;
|
|
902
|
-
/** The mime-type of the blob. */
|
|
903
900
|
mediaType: BlobMediaType;
|
|
904
|
-
/** File size in bytes. */
|
|
905
901
|
sizeBytes: number;
|
|
906
|
-
/** Human-readable filename. */
|
|
907
902
|
filename?: string;
|
|
908
|
-
}
|
|
909
|
-
|
|
903
|
+
};
|
|
904
|
+
/** Supported payload for remote URI context. */
|
|
905
|
+
type RemoteContextContent = {
|
|
910
906
|
kind: "remote";
|
|
911
|
-
/** The fully qualified URI to the external resource. */
|
|
912
907
|
uri: URI;
|
|
913
|
-
/** Optional hint for the expected mime-type at the remote destination. */
|
|
914
908
|
mediaType?: BlobMediaType;
|
|
915
909
|
};
|
|
910
|
+
/** Union of built-in context types. */
|
|
911
|
+
type DefaultContextContent = TextContextContent | JsonContextContent | BlobContextContent | RemoteContextContent;
|
|
912
|
+
/**
|
|
913
|
+
* Discriminated union of types that can be injected into the AI context.
|
|
914
|
+
* Extensions provide their own T which MUST include a unique 'kind' discriminator.
|
|
915
|
+
*/
|
|
916
|
+
type ContextContent<T = any> = DefaultContextContent | T;
|
|
916
917
|
/** A contextual item (file, snippet, or data) attached to a session or prompt. */
|
|
917
|
-
interface Context {
|
|
918
|
+
interface Context<T = any> {
|
|
918
919
|
/** Unique lookup key for this context entry. */
|
|
919
920
|
key: string;
|
|
920
921
|
/** Topics linking this context to relevant sessions or roles. */
|
|
921
922
|
topics: string[];
|
|
922
923
|
/** The actual payload of the context block. */
|
|
923
|
-
content: ContextContent
|
|
924
|
+
content: ContextContent<T>;
|
|
924
925
|
/** UTC timestamp of when the context was added. */
|
|
925
926
|
timestamp: Timestamp;
|
|
926
927
|
/** Extensible key-value store for application-specific contextual metadata. */
|
|
@@ -988,6 +989,8 @@ interface PreferenceSummary {
|
|
|
988
989
|
interface ContextSummary {
|
|
989
990
|
/** The unique key for the context item. */
|
|
990
991
|
key: string;
|
|
992
|
+
/** The kind of context (e.g. 'text', 'blob', 'task'). Used for routing. */
|
|
993
|
+
kind: string;
|
|
991
994
|
/** Associated semantic topics. */
|
|
992
995
|
topics: string[];
|
|
993
996
|
/** UTC timestamp of addition. */
|
|
@@ -1475,189 +1478,26 @@ interface SessionSnapshot {
|
|
|
1475
1478
|
}
|
|
1476
1479
|
|
|
1477
1480
|
/**
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1480
|
-
* Contains fully ranked and conflict-resolved preferences, context, and a
|
|
1481
|
-
* catalogue of blob references — but is NOT truncated and does NOT contain
|
|
1482
|
-
* resolved binary blob data. The adapter is responsible for:
|
|
1483
|
-
* - Deciding what fits within the model's context window.
|
|
1484
|
-
* - Resolving only the BlobRefs that survive truncation.
|
|
1485
|
-
* - Uploading inline blobs to the provider where required.
|
|
1486
|
-
*/
|
|
1487
|
-
interface Prompt {
|
|
1488
|
-
/** Model identifier (e.g., "claude-sonnet-4-6", "gemini-2.0-flash"). */
|
|
1489
|
-
model?: string;
|
|
1490
|
-
/** Correlates this prompt to its session for logging and evaluation. */
|
|
1491
|
-
session: UUID;
|
|
1492
|
-
/** System-level instructions, context, and preferences. */
|
|
1493
|
-
system: {
|
|
1494
|
-
/** The active role's persona string. */
|
|
1495
|
-
persona: string;
|
|
1496
|
-
/** Global or session-level instructions. */
|
|
1497
|
-
instructions?: string;
|
|
1498
|
-
/** Conflict-resolved, relevance-ordered preferences. */
|
|
1499
|
-
preferences: Preference[];
|
|
1500
|
-
/** Ranked context entries (text and json kinds only). Blob context is
|
|
1501
|
-
* represented as referential blocks in the transcript instead. */
|
|
1502
|
-
context: Context[];
|
|
1503
|
-
};
|
|
1504
|
-
/** Active conversation chain, oldest to newest. May include synthetic turns.
|
|
1505
|
-
* Image and document blocks carry a BlobRef only; the adapter resolves them. */
|
|
1506
|
-
transcript: Turn[];
|
|
1507
|
-
/**
|
|
1508
|
-
* Lightweight catalogue of every blob referenced anywhere in this prompt
|
|
1509
|
-
* (system.context or transcript), keyed by SHA256.
|
|
1510
|
-
*
|
|
1511
|
-
* Values are BlobRefs — metadata only, no binary data. The adapter uses
|
|
1512
|
-
* this catalogue to resolve or upload blobs for whichever turns and context
|
|
1513
|
-
* entries survive its truncation pass.
|
|
1514
|
-
*/
|
|
1515
|
-
blobs: Map<SHA256, BlobRef>;
|
|
1516
|
-
/** The role object — for inspection and adapter use. */
|
|
1517
|
-
role: Role;
|
|
1518
|
-
/** Model constraints to be merged by the adapter (turn > session > role). */
|
|
1519
|
-
constraints: ModelConstraintMap;
|
|
1520
|
-
/**
|
|
1521
|
-
* Non-fatal warnings generated during the build phase.
|
|
1522
|
-
* Adapters and callers should surface or log these.
|
|
1523
|
-
* Examples: summarizer failures, unresolvable blob refs.
|
|
1524
|
-
*/
|
|
1525
|
-
warnings: string[];
|
|
1526
|
-
}
|
|
1527
|
-
/**
|
|
1528
|
-
* Reflects the current state of the LLM adapter (limits, headroom, and readiness).
|
|
1529
|
-
*/
|
|
1530
|
-
interface AdapterStatus {
|
|
1531
|
-
/** Provider name (e.g., "google", "anthropic", "openai"). */
|
|
1532
|
-
provider: string;
|
|
1533
|
-
/** Model identifier (e.g., "claude-sonnet-4-6", "gemini-2.0-flash"). */
|
|
1534
|
-
model: string;
|
|
1535
|
-
/** Whether the adapter is currently able to accept requests. */
|
|
1536
|
-
ready: boolean;
|
|
1537
|
-
/** Token window limits and current usage. */
|
|
1538
|
-
window: {
|
|
1539
|
-
/** Total context window size in tokens. */
|
|
1540
|
-
size: number;
|
|
1541
|
-
/** Maximum output tokens for this model. */
|
|
1542
|
-
out: number;
|
|
1543
|
-
/** Tokens remaining — estimated or as reported by the provider. */
|
|
1544
|
-
free?: number;
|
|
1545
|
-
};
|
|
1546
|
-
/** Capability flags for this model. */
|
|
1547
|
-
feature: {
|
|
1548
|
-
/** Whether the model can process image inputs. */
|
|
1549
|
-
vision: boolean;
|
|
1550
|
-
/** Whether the model supports tool/function calling. */
|
|
1551
|
-
tools: boolean;
|
|
1552
|
-
/** Whether the model supports structured JSON output mode. */
|
|
1553
|
-
json: boolean;
|
|
1554
|
-
/** Whether the provider supports prompt caching. */
|
|
1555
|
-
cache: boolean;
|
|
1556
|
-
/** Whether the adapter supports streaming. */
|
|
1557
|
-
streaming: boolean;
|
|
1558
|
-
/** Whether the model supports extended thinking/reasoning tokens. */
|
|
1559
|
-
thinking: boolean;
|
|
1560
|
-
};
|
|
1561
|
-
/** Pricing tiers for this model. */
|
|
1562
|
-
pricing: Array<{
|
|
1563
|
-
unit: 'token' | 'call' | "image";
|
|
1564
|
-
/** Exponent: price is per 10^scale units. */
|
|
1565
|
-
scale: number;
|
|
1566
|
-
/** Price per unit in USD. */
|
|
1567
|
-
cost: {
|
|
1568
|
-
input: number;
|
|
1569
|
-
output: number;
|
|
1570
|
-
cache?: {
|
|
1571
|
-
read: number;
|
|
1572
|
-
write: number;
|
|
1573
|
-
};
|
|
1574
|
-
};
|
|
1575
|
-
}>;
|
|
1576
|
-
/** Current rate limit state. */
|
|
1577
|
-
rate: {
|
|
1578
|
-
/** Current saturation as a fraction of the most constrained limit (0.0 to 1.0). */
|
|
1579
|
-
load: number;
|
|
1580
|
-
/** Milliseconds until the next request is permitted. */
|
|
1581
|
-
timeout?: number;
|
|
1582
|
-
/** The hard limits enforced by the provider. */
|
|
1583
|
-
capacity: Array<{
|
|
1584
|
-
unit: 'token' | 'call' | string;
|
|
1585
|
-
/** Maximum units allowed per period. */
|
|
1586
|
-
max: number;
|
|
1587
|
-
/** Period length in seconds. */
|
|
1588
|
-
period: number;
|
|
1589
|
-
}>;
|
|
1590
|
-
};
|
|
1591
|
-
/** Adapter-level notes, e.g. model deprecation warnings. */
|
|
1592
|
-
notes?: string[];
|
|
1593
|
-
}
|
|
1594
|
-
/**
|
|
1595
|
-
* The result of `PreparedPrompt.execute()`. Contains the turn and derived effects.
|
|
1596
|
-
*/
|
|
1597
|
-
interface ExecuteResult {
|
|
1598
|
-
/** The newly generated assistant turn. */
|
|
1599
|
-
turn: Turn;
|
|
1600
|
-
/** Side-effect commands to dispatch against the workspace. */
|
|
1601
|
-
effects: BaseCommand[];
|
|
1602
|
-
}
|
|
1603
|
-
/**
|
|
1604
|
-
* A single labelled section of the system prompt.
|
|
1605
|
-
* Mirrors PreparedPrompt.system exactly — the assembler's output is stored
|
|
1606
|
-
* there directly, giving callers full inspection without re-parsing the string.
|
|
1481
|
+
* Registry for managing context kind definitions and their behaviors.
|
|
1607
1482
|
*/
|
|
1608
|
-
|
|
1483
|
+
declare class ContextRegistry {
|
|
1484
|
+
private readonly store;
|
|
1485
|
+
constructor();
|
|
1486
|
+
private registerDefaults;
|
|
1609
1487
|
/**
|
|
1610
|
-
*
|
|
1611
|
-
*
|
|
1612
|
-
* 'preferences' | 'context' | 'instructions'.
|
|
1613
|
-
* Extensions carry whatever label the injector provides.
|
|
1488
|
+
* Registers a new context definition.
|
|
1489
|
+
* @param definition The context definition to register.
|
|
1614
1490
|
*/
|
|
1615
|
-
|
|
1616
|
-
/** Text content exactly as it will be sent to the model. */
|
|
1617
|
-
content: string;
|
|
1618
|
-
/** Optional structured metadata for richer UI display or tooling. */
|
|
1619
|
-
metadata?: Record<string, any>;
|
|
1620
|
-
}
|
|
1621
|
-
/**
|
|
1622
|
-
* The complete, final prompt exactly as the model will receive it.
|
|
1623
|
-
* Generic, provider-agnostic, fully inspectable, and executable.
|
|
1624
|
-
*/
|
|
1625
|
-
interface PreparedPrompt {
|
|
1626
|
-
/** Model identifier (e.g., "claude-sonnet-4-6", "gemini-2.0-flash"). */
|
|
1627
|
-
model: string;
|
|
1628
|
-
/** The complete system instruction broken into labelled sections for inspection. */
|
|
1629
|
-
instructions: Array<PromptSection>;
|
|
1630
|
-
/** Final transcript turns that will be sent after adapter-level truncation. */
|
|
1631
|
-
transcript: Turn[];
|
|
1632
|
-
/** Final context entries included after adapter-level truncation. */
|
|
1633
|
-
context: Context[];
|
|
1634
|
-
/** Final preferences included after adapter-level truncation. */
|
|
1635
|
-
preferences: Preference[];
|
|
1636
|
-
/** The resolved model constraints for this request. */
|
|
1637
|
-
constraints: ModelConstraint;
|
|
1638
|
-
/** Token accounting (estimated or exact). */
|
|
1639
|
-
tokens: {
|
|
1640
|
-
/** Breakdown by section. Keys are adapter-defined. */
|
|
1641
|
-
breakdown: Record<string, number>;
|
|
1642
|
-
/** Total input tokens — estimated or exact. */
|
|
1643
|
-
total: number;
|
|
1644
|
-
/** Whether total is an estimate or exact (provider-supplied). */
|
|
1645
|
-
source: 'estimated' | 'exact';
|
|
1646
|
-
/** Maximum output tokens configured for this request. */
|
|
1647
|
-
output?: number;
|
|
1648
|
-
/** Tokens remaining in the context window after this prompt. */
|
|
1649
|
-
remaining?: number;
|
|
1650
|
-
};
|
|
1491
|
+
register(definition: ContextDefinition): void;
|
|
1651
1492
|
/**
|
|
1652
|
-
*
|
|
1653
|
-
* @
|
|
1493
|
+
* Retrieves a context definition by kind.
|
|
1494
|
+
* @param kind The context kind to retrieve.
|
|
1654
1495
|
*/
|
|
1655
|
-
|
|
1496
|
+
get(kind: string): ContextDefinition | undefined;
|
|
1656
1497
|
/**
|
|
1657
|
-
*
|
|
1658
|
-
* Present only if the adapter and model support streaming.
|
|
1498
|
+
* Lists all registered context definitions.
|
|
1659
1499
|
*/
|
|
1660
|
-
|
|
1500
|
+
list(): ContextDefinition[];
|
|
1661
1501
|
}
|
|
1662
1502
|
|
|
1663
1503
|
/**
|
|
@@ -1886,12 +1726,204 @@ interface WorkspaceServices {
|
|
|
1886
1726
|
* Self-describing catalogue of all known content block types.
|
|
1887
1727
|
*/
|
|
1888
1728
|
blockRegistry: ContentBlockRegistry;
|
|
1729
|
+
/**
|
|
1730
|
+
* Registry for managing custom context kinds.
|
|
1731
|
+
*/
|
|
1732
|
+
contextRegistry: ContextRegistry;
|
|
1889
1733
|
/**
|
|
1890
1734
|
* Model registry
|
|
1891
1735
|
*/
|
|
1892
1736
|
models: ModelRegistry;
|
|
1893
1737
|
}
|
|
1894
1738
|
|
|
1739
|
+
/**
|
|
1740
|
+
* Output of PromptBuilder.build(). Input to LLMAdapter.resolve().
|
|
1741
|
+
*
|
|
1742
|
+
* Contains fully ranked and conflict-resolved preferences, context, and a
|
|
1743
|
+
* catalogue of blob references — but is NOT truncated and does NOT contain
|
|
1744
|
+
* resolved binary blob data. The adapter is responsible for:
|
|
1745
|
+
* - Deciding what fits within the model's context window.
|
|
1746
|
+
* - Resolving only the BlobRefs that survive truncation.
|
|
1747
|
+
* - Uploading inline blobs to the provider where required.
|
|
1748
|
+
*/
|
|
1749
|
+
interface Prompt {
|
|
1750
|
+
/** Model identifier (e.g., "claude-sonnet-4-6", "gemini-2.0-flash"). */
|
|
1751
|
+
model?: string;
|
|
1752
|
+
/** Correlates this prompt to its session for logging and evaluation. */
|
|
1753
|
+
session: UUID;
|
|
1754
|
+
/** System-level instructions, context, and preferences. */
|
|
1755
|
+
system: {
|
|
1756
|
+
/** The active role's persona string. */
|
|
1757
|
+
persona: string;
|
|
1758
|
+
/** Global or session-level instructions. */
|
|
1759
|
+
instructions?: string;
|
|
1760
|
+
/** Conflict-resolved, relevance-ordered preferences. */
|
|
1761
|
+
preferences: Preference[];
|
|
1762
|
+
/** Ranked context entries (text and json kinds only). Blob context is
|
|
1763
|
+
* represented as referential blocks in the transcript instead. */
|
|
1764
|
+
context: Context[];
|
|
1765
|
+
/** Additional sections injected by the adapter or application layer. */
|
|
1766
|
+
extensions?: AssemblerExtension[];
|
|
1767
|
+
};
|
|
1768
|
+
/** Active conversation chain, oldest to newest. May include synthetic turns.
|
|
1769
|
+
* Image and document blocks carry a BlobRef only; the adapter resolves them. */
|
|
1770
|
+
transcript: Turn[];
|
|
1771
|
+
/**
|
|
1772
|
+
* Lightweight catalogue of every blob referenced anywhere in this prompt
|
|
1773
|
+
* (system.context or transcript), keyed by SHA256.
|
|
1774
|
+
*
|
|
1775
|
+
* Values are BlobRefs — metadata only, no binary data. The adapter uses
|
|
1776
|
+
* this catalogue to resolve or upload blobs for whichever turns and context
|
|
1777
|
+
* entries survive its truncation pass.
|
|
1778
|
+
*/
|
|
1779
|
+
blobs: Map<SHA256, BlobRef>;
|
|
1780
|
+
/** The role object — for inspection and adapter use. */
|
|
1781
|
+
role: Role;
|
|
1782
|
+
/** Model constraints to be merged by the adapter (turn > session > role). */
|
|
1783
|
+
constraints: ModelConstraintMap;
|
|
1784
|
+
/**
|
|
1785
|
+
* Non-fatal warnings generated during the build phase.
|
|
1786
|
+
* Adapters and callers should surface or log these.
|
|
1787
|
+
* Examples: summarizer failures, unresolvable blob refs.
|
|
1788
|
+
*/
|
|
1789
|
+
warnings: string[];
|
|
1790
|
+
}
|
|
1791
|
+
/**
|
|
1792
|
+
* Reflects the current state of the LLM adapter (limits, headroom, and readiness).
|
|
1793
|
+
*/
|
|
1794
|
+
interface AdapterStatus {
|
|
1795
|
+
/** Provider name (e.g., "google", "anthropic", "openai"). */
|
|
1796
|
+
provider: string;
|
|
1797
|
+
/** Model identifier (e.g., "claude-sonnet-4-6", "gemini-2.0-flash"). */
|
|
1798
|
+
model: string;
|
|
1799
|
+
/** Whether the adapter is currently able to accept requests. */
|
|
1800
|
+
ready: boolean;
|
|
1801
|
+
/** Token window limits and current usage. */
|
|
1802
|
+
window: {
|
|
1803
|
+
/** Total context window size in tokens. */
|
|
1804
|
+
size: number;
|
|
1805
|
+
/** Maximum output tokens for this model. */
|
|
1806
|
+
out: number;
|
|
1807
|
+
/** Tokens remaining — estimated or as reported by the provider. */
|
|
1808
|
+
free?: number;
|
|
1809
|
+
};
|
|
1810
|
+
/** Capability flags for this model. */
|
|
1811
|
+
feature: {
|
|
1812
|
+
/** Whether the model can process image inputs. */
|
|
1813
|
+
vision: boolean;
|
|
1814
|
+
/** Whether the model supports tool/function calling. */
|
|
1815
|
+
tools: boolean;
|
|
1816
|
+
/** Whether the model supports structured JSON output mode. */
|
|
1817
|
+
json: boolean;
|
|
1818
|
+
/** Whether the provider supports prompt caching. */
|
|
1819
|
+
cache: boolean;
|
|
1820
|
+
/** Whether the adapter supports streaming. */
|
|
1821
|
+
streaming: boolean;
|
|
1822
|
+
/** Whether the model supports extended thinking/reasoning tokens. */
|
|
1823
|
+
thinking: boolean;
|
|
1824
|
+
};
|
|
1825
|
+
/** Pricing tiers for this model. */
|
|
1826
|
+
pricing: Array<{
|
|
1827
|
+
unit: "token" | "call" | "image";
|
|
1828
|
+
/** Exponent: price is per 10^scale units. */
|
|
1829
|
+
scale: number;
|
|
1830
|
+
/** Price per unit in USD. */
|
|
1831
|
+
cost: {
|
|
1832
|
+
input: number;
|
|
1833
|
+
output: number;
|
|
1834
|
+
cache?: {
|
|
1835
|
+
read: number;
|
|
1836
|
+
write: number;
|
|
1837
|
+
};
|
|
1838
|
+
};
|
|
1839
|
+
}>;
|
|
1840
|
+
/** Current rate limit state. */
|
|
1841
|
+
rate: {
|
|
1842
|
+
/** Current saturation as a fraction of the most constrained limit (0.0 to 1.0). */
|
|
1843
|
+
load: number;
|
|
1844
|
+
/** Milliseconds until the next request is permitted. */
|
|
1845
|
+
timeout?: number;
|
|
1846
|
+
/** The hard limits enforced by the provider. */
|
|
1847
|
+
capacity: Array<{
|
|
1848
|
+
unit: "token" | "call" | string;
|
|
1849
|
+
/** Maximum units allowed per period. */
|
|
1850
|
+
max: number;
|
|
1851
|
+
/** Period length in seconds. */
|
|
1852
|
+
period: number;
|
|
1853
|
+
}>;
|
|
1854
|
+
};
|
|
1855
|
+
/** Adapter-level notes, e.g. model deprecation warnings. */
|
|
1856
|
+
notes?: string[];
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* The result of `PreparedPrompt.execute()`. Contains the turn and derived effects.
|
|
1860
|
+
*/
|
|
1861
|
+
interface ExecuteResult {
|
|
1862
|
+
/** The newly generated assistant turn. */
|
|
1863
|
+
turn: Turn;
|
|
1864
|
+
/** Side-effect commands to dispatch against the workspace. */
|
|
1865
|
+
effects: BaseCommand[];
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* A single labelled section of the system prompt.
|
|
1869
|
+
* Mirrors PreparedPrompt.system exactly — the assembler's output is stored
|
|
1870
|
+
* there directly, giving callers full inspection without re-parsing the string.
|
|
1871
|
+
*/
|
|
1872
|
+
interface PromptSection {
|
|
1873
|
+
/**
|
|
1874
|
+
* Origin label for this section.
|
|
1875
|
+
* Core sections use fixed labels: 'operating-system' | 'persona' |
|
|
1876
|
+
* 'preferences' | 'context' | 'instructions'.
|
|
1877
|
+
* Extensions carry whatever label the injector provides.
|
|
1878
|
+
*/
|
|
1879
|
+
label: string;
|
|
1880
|
+
/** Text content exactly as it will be sent to the model. */
|
|
1881
|
+
content: string;
|
|
1882
|
+
/** Optional structured metadata for richer UI display or tooling. */
|
|
1883
|
+
metadata?: Record<string, any>;
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* The complete, final prompt exactly as the model will receive it.
|
|
1887
|
+
* Generic, provider-agnostic, fully inspectable, and executable.
|
|
1888
|
+
*/
|
|
1889
|
+
interface PreparedPrompt {
|
|
1890
|
+
/** Model identifier (e.g., "claude-sonnet-4-6", "gemini-2.0-flash"). */
|
|
1891
|
+
model: string;
|
|
1892
|
+
/** The complete system instruction broken into labelled sections for inspection. */
|
|
1893
|
+
instructions: Array<PromptSection>;
|
|
1894
|
+
/** Final transcript turns that will be sent after adapter-level truncation. */
|
|
1895
|
+
transcript: Turn[];
|
|
1896
|
+
/** Final context entries included after adapter-level truncation. */
|
|
1897
|
+
context: Context[];
|
|
1898
|
+
/** Final preferences included after adapter-level truncation. */
|
|
1899
|
+
preferences: Preference[];
|
|
1900
|
+
/** The resolved model constraints for this request. */
|
|
1901
|
+
constraints: ModelConstraint;
|
|
1902
|
+
/** Token accounting (estimated or exact). */
|
|
1903
|
+
tokens: {
|
|
1904
|
+
/** Breakdown by section. Keys are adapter-defined. */
|
|
1905
|
+
breakdown: Record<string, number>;
|
|
1906
|
+
/** Total input tokens — estimated or exact. */
|
|
1907
|
+
total: number;
|
|
1908
|
+
/** Whether total is an estimate or exact (provider-supplied). */
|
|
1909
|
+
source: "estimated" | "exact";
|
|
1910
|
+
/** Maximum output tokens configured for this request. */
|
|
1911
|
+
output?: number;
|
|
1912
|
+
/** Tokens remaining in the context window after this prompt. */
|
|
1913
|
+
remaining?: number;
|
|
1914
|
+
};
|
|
1915
|
+
/**
|
|
1916
|
+
* Sends this prompt to the model.
|
|
1917
|
+
* @returns The parsed assistant Turn plus any execution side-effects.
|
|
1918
|
+
*/
|
|
1919
|
+
execute(): Promise<Result<ExecuteResult, WorkspaceError>>;
|
|
1920
|
+
/**
|
|
1921
|
+
* Streaming variant of execute(). Yields partial turns as tokens arrive.
|
|
1922
|
+
* Present only if the adapter and model support streaming.
|
|
1923
|
+
*/
|
|
1924
|
+
executeStream?(): AsyncIterable<Partial<Turn> | ExecuteResult>;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1895
1927
|
/**
|
|
1896
1928
|
* A simple LRU (Least Recently Used) cache implementation.
|
|
1897
1929
|
* Used for caching frequently accessed entities in memory.
|
|
@@ -2048,17 +2080,23 @@ declare const COLLECTIONS: {
|
|
|
2048
2080
|
readonly BLOB: "blob";
|
|
2049
2081
|
readonly TOPIC: "topic";
|
|
2050
2082
|
};
|
|
2051
|
-
type Collections = typeof COLLECTIONS[keyof typeof COLLECTIONS];
|
|
2083
|
+
type Collections = (typeof COLLECTIONS)[keyof typeof COLLECTIONS];
|
|
2052
2084
|
|
|
2053
2085
|
declare class ContextStore implements Store<Context, ContextSummary, string> {
|
|
2054
2086
|
private readonly collection;
|
|
2055
2087
|
private readonly cache;
|
|
2056
|
-
|
|
2057
|
-
|
|
2088
|
+
private readonly registry?;
|
|
2089
|
+
private readonly delegates;
|
|
2090
|
+
constructor(collection: Collection<Context>, cache: LRUCache<string, Context>, registry?: ContextRegistry | undefined);
|
|
2091
|
+
/**
|
|
2092
|
+
* Registers a specialized store for a specific context kind.
|
|
2093
|
+
*/
|
|
2094
|
+
registerDelegate(kind: string, store: Store<Context, ContextSummary, string>): void;
|
|
2095
|
+
get(key: string, kind?: string): Promise<Context | null>;
|
|
2058
2096
|
add(context: Context): Promise<void>;
|
|
2059
2097
|
list(): Promise<Context[]>;
|
|
2060
|
-
update(key: string, updates: Partial<Context
|
|
2061
|
-
delete(key: string): Promise<boolean>;
|
|
2098
|
+
update(key: string, updates: Partial<Context>, kind?: string): Promise<Context | null>;
|
|
2099
|
+
delete(key: string, kind?: string): Promise<boolean>;
|
|
2062
2100
|
/**
|
|
2063
2101
|
* Retrieves all context items referenced by the given topics using the in-memory index.
|
|
2064
2102
|
*/
|
|
@@ -2183,6 +2221,38 @@ declare class WorkspaceStore implements Store<WorkspaceMetadata, WorkspaceMetada
|
|
|
2183
2221
|
* A function that rebuilds a portion of the workspace index from persistent storage.
|
|
2184
2222
|
*/
|
|
2185
2223
|
type Indexer = (ctx: WorkspaceContext) => Promise<DeepPartial<Workspace>>;
|
|
2224
|
+
/**
|
|
2225
|
+
* Definition of a specific kind of context and how the system interacts with it.
|
|
2226
|
+
*/
|
|
2227
|
+
interface ContextDefinition<T = any> {
|
|
2228
|
+
/** Unique discriminator for this context kind (e.g., 'text', 'blob', 'task'). */
|
|
2229
|
+
kind: string;
|
|
2230
|
+
/**
|
|
2231
|
+
* Where this context prefers to live in the prompt.
|
|
2232
|
+
* 'system' -> Rendered into the system instructions.
|
|
2233
|
+
* 'transcript' -> Rendered as a synthetic turn prefixing the transcript.
|
|
2234
|
+
*/
|
|
2235
|
+
target: "system" | "transcript";
|
|
2236
|
+
/**
|
|
2237
|
+
* Transforms the context item into one or more content blocks.
|
|
2238
|
+
* If these blocks contain BlobRefs, the PromptBuilder will automatically
|
|
2239
|
+
* catalogue them for the adapter.
|
|
2240
|
+
*/
|
|
2241
|
+
render(context: Context<T>): ContentBlock | ContentBlock[];
|
|
2242
|
+
/**
|
|
2243
|
+
* Returns a plain text representation for the RAG/retriever system.
|
|
2244
|
+
*/
|
|
2245
|
+
toString(context: Context<T>): string;
|
|
2246
|
+
/**
|
|
2247
|
+
* Produces a condensed summary for the workspace index projection.
|
|
2248
|
+
*/
|
|
2249
|
+
summarize(context: Context<T>): ContextSummary;
|
|
2250
|
+
/**
|
|
2251
|
+
* Optional factory for a custom store for this context kind.
|
|
2252
|
+
* If omitted, the default 'context' collection is used.
|
|
2253
|
+
*/
|
|
2254
|
+
store?: (ctx: WorkspaceContext) => Store<Context<T>, ContextSummary, string>;
|
|
2255
|
+
}
|
|
2186
2256
|
/**
|
|
2187
2257
|
* A bundle of domain-specific logic that can be plugged into the workspace.
|
|
2188
2258
|
* Allows app builders to group related schemas, reducers, stores, and blocks.
|
|
@@ -2200,6 +2270,8 @@ interface WorkspaceExtension {
|
|
|
2200
2270
|
stores?: (ctx: Omit<WorkspaceContext, "workspace">) => Record<string, Store<any>> | Promise<Record<string, Store<any>>>;
|
|
2201
2271
|
/** Content block definitions for the LLM adapter. */
|
|
2202
2272
|
blocks?: ContentBlockDefinition[];
|
|
2273
|
+
/** Custom context kind definitions. */
|
|
2274
|
+
contexts?: ContextDefinition[];
|
|
2203
2275
|
}
|
|
2204
2276
|
/**
|
|
2205
2277
|
* The full set of stores passed to every reducer and middleware call.
|
|
@@ -2627,9 +2699,9 @@ declare function computeSHA256(data: Uint8Array): Promise<SHA256>;
|
|
|
2627
2699
|
*/
|
|
2628
2700
|
declare function bufferToBase64(buffer: Uint8Array): string;
|
|
2629
2701
|
/**
|
|
2630
|
-
* Short, deterministic hash of a string (4 chars in base36).
|
|
2631
|
-
* Suitable for AI-friendly reference tokens.
|
|
2632
|
-
*/
|
|
2702
|
+
* Short, deterministic hash of a string (4 chars in base36).
|
|
2703
|
+
* Suitable for AI-friendly reference tokens.
|
|
2704
|
+
*/
|
|
2633
2705
|
declare function shortHash(s: string, length?: number): string;
|
|
2634
2706
|
declare function getExtension<K extends string, V>(index: Index, key: K): Record<string, V>;
|
|
2635
2707
|
|
|
@@ -2666,4 +2738,4 @@ declare function createWorkspace(params: CreateWorkspaceParams): Promise<{
|
|
|
2666
2738
|
services: WorkspaceServices;
|
|
2667
2739
|
}>;
|
|
2668
2740
|
|
|
2669
|
-
export { type AddContext, type AddPreference, type AddRole, type AddSessionTopics, type AddTopic, type AddTurn, type AuthRequest, type BackendError, type BaseCommand, type BaseContentBlock, type BlobCommand, type BlobError, type BlobMediaType, type BlobRecord, type BlobRef, type BlobResolver, type BranchInfo, type BranchTurn, COLLECTIONS, type Collections, type Command, type ContentBlock, type Context, type ContextContent, type ContextRetriever, type ContextSummary, type CreateSession, type CreateWorkspace, type CreateWorkspaceParams, type DeepPartial, type DeleteContext, type DeletePreference, type DeleteRole, type DeleteSession, type DeleteTopic, type DeleteTurn, type DocumentBlock, type DocumentMediaType, type DuplicateKeyError, EMPTY_SYSTEM_ROLE, type EditTurn, type ForkSession, type ImageBlock, type ImageMediaType, type Index, type IndexExtensions, type Indexer, type InvalidCommandError, type LLMAdapter, type LLMAdapterStatic, LRUCache, type MergeTopics, type ModelConstraint, type ModelConstraintMap, type ModelName, type ModelProfile, type ModelRegistry, type NotFoundError, type OverrideSessionPreferences, type PermissionDeniedError, type PermissionGuard, type Preference, type PreferenceSummary, type Project, type PromptBuilder, type PromptBuilderOptions, type PurgeBlob, type RecordBlobRemoteId, type RegisterBlob, type ReleaseBlob, type ResolvedBlob, type ResolvedSession, type Result, type RetainBlob, type Role, type RoleSummary, type RoleTransitionBlock, type SHA256, Session, SessionManager, type SessionMetadata, type SessionSnapshot, type Settings, type Store, type Summarizer, type SummaryBlock, type SwitchSessionRole, type SyncWorkspace, type SystemActor, type TextBlock, type ThinkingBlock, type Timestamp, type ToolCall, type ToolCallCommand, type ToolRegistry, type ToolResultBlock, type ToolSummary, type ToolUseBlock, type Topic, type TopicIndex, type Turn, TurnBuilder, type TurnKey, type TurnNode, type TurnProcessor, type TurnRef, TurnTree, type URI, type UUID, type UpdateContext, type UpdatePreference, type UpdateRole, type UpdateSession, type UpdateTopic, type UpdateTurn, type Workspace, type WorkspaceBundle, type WorkspaceContext, type WorkspaceDatabase, type WorkspaceError, type WorkspaceEvents, type WorkspaceExtension, WorkspaceManager, type WorkspaceMiddleware, type WorkspaceReducer, bufferToBase64, computeSHA256, createWorkspace, createWorkspaceDatabase, del, error, getExtension, merge, ok, omitNullUndefined, shortHash, success };
|
|
2741
|
+
export { type AddContext, type AddPreference, type AddRole, type AddSessionTopics, type AddTopic, type AddTurn, type AuthRequest, type BackendError, type BaseCommand, type BaseContentBlock, type BlobCommand, type BlobContextContent, type BlobError, type BlobMediaType, type BlobRecord, type BlobRef, type BlobResolver, type BranchInfo, type BranchTurn, COLLECTIONS, type Collections, type Command, type ContentBlock, type Context, type ContextContent, type ContextDefinition, type ContextRetriever, type ContextSummary, type CreateSession, type CreateWorkspace, type CreateWorkspaceParams, type DeepPartial, type DefaultContextContent, type DeleteContext, type DeletePreference, type DeleteRole, type DeleteSession, type DeleteTopic, type DeleteTurn, type DocumentBlock, type DocumentMediaType, type DuplicateKeyError, EMPTY_SYSTEM_ROLE, type EditTurn, type ForkSession, type ImageBlock, type ImageMediaType, type Index, type IndexExtensions, type Indexer, type InvalidCommandError, type JsonContextContent, type LLMAdapter, type LLMAdapterStatic, LRUCache, type MergeTopics, type ModelConstraint, type ModelConstraintMap, type ModelName, type ModelProfile, type ModelRegistry, type NotFoundError, type OverrideSessionPreferences, type PermissionDeniedError, type PermissionGuard, type Preference, type PreferenceSummary, type Project, type PromptBuilder, type PromptBuilderOptions, type PurgeBlob, type RecordBlobRemoteId, type RegisterBlob, type ReleaseBlob, type RemoteContextContent, type ResolvedBlob, type ResolvedSession, type Result, type RetainBlob, type Role, type RoleSummary, type RoleTransitionBlock, type SHA256, Session, SessionManager, type SessionMetadata, type SessionSnapshot, type Settings, type Store, type Summarizer, type SummaryBlock, type SwitchSessionRole, type SyncWorkspace, type SystemActor, type TextBlock, type TextContextContent, type ThinkingBlock, type Timestamp, type ToolCall, type ToolCallCommand, type ToolRegistry, type ToolResultBlock, type ToolSummary, type ToolUseBlock, type Topic, type TopicIndex, type Turn, TurnBuilder, type TurnKey, type TurnNode, type TurnProcessor, type TurnRef, TurnTree, type URI, type UUID, type UpdateContext, type UpdatePreference, type UpdateRole, type UpdateSession, type UpdateTopic, type UpdateTurn, type Workspace, type WorkspaceBundle, type WorkspaceContext, type WorkspaceDatabase, type WorkspaceError, type WorkspaceEvents, type WorkspaceExtension, WorkspaceManager, type WorkspaceMiddleware, type WorkspaceReducer, bufferToBase64, computeSHA256, createWorkspace, createWorkspaceDatabase, del, error, getExtension, merge, ok, omitNullUndefined, shortHash, success };
|