@ap3x/agent-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/agent-errors.d.ts +54 -0
- package/dist/agent-errors.d.ts.map +1 -0
- package/dist/agent-loop.d.ts +30 -0
- package/dist/agent-loop.d.ts.map +1 -0
- package/dist/agent.d.ts +160 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/backend.d.ts +67 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/compaction.d.ts +147 -0
- package/dist/compaction.d.ts.map +1 -0
- package/dist/concurrency.d.ts +32 -0
- package/dist/concurrency.d.ts.map +1 -0
- package/dist/conversation.d.ts +215 -0
- package/dist/conversation.d.ts.map +1 -0
- package/dist/env.d.ts +125 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/harness.d.ts +110 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4153 -0
- package/dist/loader.d.ts +142 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/logger.d.ts +36 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/output-formatter.d.ts +27 -0
- package/dist/output-formatter.d.ts.map +1 -0
- package/dist/prompt-templates.d.ts +78 -0
- package/dist/prompt-templates.d.ts.map +1 -0
- package/dist/result.d.ts +26 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/serialization.d.ts +75 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/session-repo.d.ts +90 -0
- package/dist/session-repo.d.ts.map +1 -0
- package/dist/session.d.ts +251 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/shell-blocklist.d.ts +18 -0
- package/dist/shell-blocklist.d.ts.map +1 -0
- package/dist/skills.d.ts +95 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/system-prompt.d.ts +90 -0
- package/dist/system-prompt.d.ts.map +1 -0
- package/dist/tools.d.ts +61 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/types.d.ts +320 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/uuid.d.ts +23 -0
- package/dist/uuid.d.ts.map +1 -0
- package/package.json +33 -0
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent loading + registration.
|
|
3
|
+
*
|
|
4
|
+
* - {@link AgentLoader} parses agent *specifications* from Markdown (YAML
|
|
5
|
+
* frontmatter), YAML, or CSV files. It does not construct runtime agents (the
|
|
6
|
+
* orchestration layer maps specs → `AgentBackend`s); it produces validated
|
|
7
|
+
* {@link AgentSpec} objects.
|
|
8
|
+
*
|
|
9
|
+
* - {@link AgentRegistry} is a name-keyed store of agent records with add/get/
|
|
10
|
+
* list/query/find-by-name/find-by-id. Records are validated against TypeBox
|
|
11
|
+
* schemas ({@link AgentConfigSchema} / {@link AgentRegistrySchema}).
|
|
12
|
+
*
|
|
13
|
+
* Concurrency uses `Promise.all` (Node is single-threaded); the markdown/yaml/csv parsers are
|
|
14
|
+
* hand-rolled so the accepted grammar is fully specified here and dependency-free.
|
|
15
|
+
*/
|
|
16
|
+
import { type Static } from "@ap3x/ai";
|
|
17
|
+
/** TypeBox schema for a parsed agent specification. */
|
|
18
|
+
export declare const AgentSpecSchema: import("@sinclair/typebox").TObject<{
|
|
19
|
+
name: import("@sinclair/typebox").TString;
|
|
20
|
+
description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
21
|
+
modelName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
22
|
+
systemPrompt: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
23
|
+
temperature: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
24
|
+
maxLoops: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
|
|
25
|
+
maxTokens: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
|
|
26
|
+
contextLength: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
|
|
27
|
+
outputType: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
28
|
+
autosave: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
29
|
+
verbose: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
30
|
+
streamingOn: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
31
|
+
dynamicTemperatureEnabled: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
32
|
+
retryAttempts: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
|
|
33
|
+
userName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
34
|
+
}>;
|
|
35
|
+
/** A validated agent specification produced by {@link AgentLoader}. */
|
|
36
|
+
export type AgentSpec = Static<typeof AgentSpecSchema>;
|
|
37
|
+
/** Parse YAML frontmatter from markdown content, returning the data + body. */
|
|
38
|
+
export declare function parseYamlFrontmatter(content: string): {
|
|
39
|
+
frontmatter: Record<string, unknown>;
|
|
40
|
+
body: string;
|
|
41
|
+
};
|
|
42
|
+
/** Loads agent specifications from Markdown, YAML, or CSV files. */
|
|
43
|
+
export declare class AgentLoader {
|
|
44
|
+
readonly concurrent: boolean;
|
|
45
|
+
constructor(options?: {
|
|
46
|
+
concurrent?: boolean;
|
|
47
|
+
});
|
|
48
|
+
/** Parse one markdown file (YAML frontmatter + body as system prompt). */
|
|
49
|
+
loadAgentFromMarkdown(filePath: string): Promise<AgentSpec>;
|
|
50
|
+
/** Parse one or more markdown files. */
|
|
51
|
+
loadAgentsFromMarkdown(filePaths: string | string[], options?: {
|
|
52
|
+
concurrent?: boolean;
|
|
53
|
+
}): Promise<AgentSpec[]>;
|
|
54
|
+
/** Parse a YAML file containing one agent or a list under `agents`. */
|
|
55
|
+
loadAgentsFromYaml(yamlFile: string): Promise<AgentSpec[]>;
|
|
56
|
+
/** Parse several YAML files. */
|
|
57
|
+
loadManyAgentsFromYaml(yamlFiles: string[]): Promise<AgentSpec[][]>;
|
|
58
|
+
/** Parse a CSV file (first row is the header). */
|
|
59
|
+
loadAgentsFromCsv(csvFile: string): Promise<AgentSpec[]>;
|
|
60
|
+
/** Dispatch by file extension (.md / .yaml / .yml / .csv). */
|
|
61
|
+
auto(filePath: string): Promise<AgentSpec[]>;
|
|
62
|
+
/** Load a single spec from a file via {@link auto}. */
|
|
63
|
+
loadSingleAgent(filePath: string): Promise<AgentSpec>;
|
|
64
|
+
/** Load specs from several files (each may yield multiple), flattened. */
|
|
65
|
+
loadMultipleAgents(filePaths: string[]): Promise<AgentSpec[]>;
|
|
66
|
+
}
|
|
67
|
+
/** TypeBox schema for a single registry entry. */
|
|
68
|
+
export declare const AgentConfigSchema: import("@sinclair/typebox").TObject<{
|
|
69
|
+
uuid: import("@sinclair/typebox").TString;
|
|
70
|
+
name: import("@sinclair/typebox").TString;
|
|
71
|
+
description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
72
|
+
timeAdded: import("@sinclair/typebox").TString;
|
|
73
|
+
config: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
|
|
74
|
+
}>;
|
|
75
|
+
/** A validated registry entry. */
|
|
76
|
+
export type AgentConfig = Static<typeof AgentConfigSchema>;
|
|
77
|
+
/** TypeBox schema for the whole registry. */
|
|
78
|
+
export declare const AgentRegistrySchema: import("@sinclair/typebox").TObject<{
|
|
79
|
+
name: import("@sinclair/typebox").TString;
|
|
80
|
+
description: import("@sinclair/typebox").TString;
|
|
81
|
+
agents: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
82
|
+
uuid: import("@sinclair/typebox").TString;
|
|
83
|
+
name: import("@sinclair/typebox").TString;
|
|
84
|
+
description: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
85
|
+
timeAdded: import("@sinclair/typebox").TString;
|
|
86
|
+
config: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
|
|
87
|
+
}>>;
|
|
88
|
+
timeRegistryCreated: import("@sinclair/typebox").TString;
|
|
89
|
+
numberOfAgents: import("@sinclair/typebox").TInteger;
|
|
90
|
+
}>;
|
|
91
|
+
/** A validated registry snapshot. */
|
|
92
|
+
export type AgentRegistrySnapshot = Static<typeof AgentRegistrySchema>;
|
|
93
|
+
/** The minimal shape a registered agent must expose. */
|
|
94
|
+
export interface RegistrableAgent {
|
|
95
|
+
agentName?: string;
|
|
96
|
+
name?: string;
|
|
97
|
+
id?: string;
|
|
98
|
+
description?: string;
|
|
99
|
+
toDict?: () => Record<string, unknown>;
|
|
100
|
+
[key: string]: unknown;
|
|
101
|
+
}
|
|
102
|
+
/** A name-keyed store of agents with query + find helpers. */
|
|
103
|
+
export declare class AgentRegistry<TAgent extends RegistrableAgent = RegistrableAgent> {
|
|
104
|
+
readonly name: string;
|
|
105
|
+
readonly description: string;
|
|
106
|
+
private readonly agents;
|
|
107
|
+
private readonly timeCreated;
|
|
108
|
+
constructor(options?: {
|
|
109
|
+
name?: string;
|
|
110
|
+
description?: string;
|
|
111
|
+
agents?: TAgent[];
|
|
112
|
+
});
|
|
113
|
+
/** Add an agent. Throws if the name is already taken. */
|
|
114
|
+
add(agent: TAgent): void;
|
|
115
|
+
/** Add several agents. */
|
|
116
|
+
addMany(agents: TAgent[]): void;
|
|
117
|
+
/** Delete an agent by name. Throws if it does not exist. */
|
|
118
|
+
delete(name: string): void;
|
|
119
|
+
/** Replace an agent by name. Throws if it does not exist. */
|
|
120
|
+
updateAgent(name: string, newAgent: TAgent): void;
|
|
121
|
+
/** Get an agent by name. Throws if it does not exist. */
|
|
122
|
+
get(name: string): TAgent;
|
|
123
|
+
/** List all registered agent names. */
|
|
124
|
+
listAgents(): string[];
|
|
125
|
+
/** Return all registered agents. */
|
|
126
|
+
returnAllAgents(): TAgent[];
|
|
127
|
+
/** Filter agents by a predicate (or return all when omitted). */
|
|
128
|
+
query(condition?: (agent: TAgent) => boolean): TAgent[];
|
|
129
|
+
/** Find an agent by name (undefined if absent). */
|
|
130
|
+
findAgentByName(name: string): TAgent | undefined;
|
|
131
|
+
/** Find an agent by id (undefined if absent). */
|
|
132
|
+
findAgentById(id: string): TAgent | undefined;
|
|
133
|
+
/** Number of registered agents. */
|
|
134
|
+
get size(): number;
|
|
135
|
+
/** Serialize every agent's `toDict()` keyed by name. */
|
|
136
|
+
agentsToJson(): string;
|
|
137
|
+
/** Build a validated {@link AgentConfig} record for an agent. */
|
|
138
|
+
agentToModel(agent: TAgent): AgentConfig;
|
|
139
|
+
/** A validated snapshot of the whole registry. */
|
|
140
|
+
toSchema(): AgentRegistrySnapshot;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,UAAU,CAAC;AAI7C,uDAAuD;AACvD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;EAgB1B,CAAC;AAEH,uEAAuE;AACvE,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AA+DvD,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG;IACrD,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;CACd,CAyBA;AAiCD,oEAAoE;AACpE,qBAAa,WAAW;IACtB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;gBAEjB,OAAO,GAAE;QAAE,UAAU,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M,GAAG,SAAS;IAIjD,iDAAiD;IACjD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAO7C,mCAAmC;IACnC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,wDAAwD;IACxD,YAAY,IAAI,MAAM;IAQtB,iEAAiE;IACjE,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAUxC,kDAAkD;IAClD,QAAQ,IAAI,qBAAqB;CASlC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tiny, dependency-free leveled logger for AP3X library code.
|
|
3
|
+
*
|
|
4
|
+
* A library must be QUIET by default — stray `console.warn`/`console.error`
|
|
5
|
+
* calls from deep in the orchestration layer leak into a host application's
|
|
6
|
+
* stderr (and into test output). This logger gates every emission behind an
|
|
7
|
+
* active level that DEFAULTS TO `silent`; a host opts in by setting the
|
|
8
|
+
* `AP3X_LOG_LEVEL` environment variable (case-insensitive) or by calling
|
|
9
|
+
* {@link setLogLevel}.
|
|
10
|
+
*
|
|
11
|
+
* Levels are ordered by increasing verbosity:
|
|
12
|
+
*
|
|
13
|
+
* silent < error < warn < info < debug
|
|
14
|
+
*
|
|
15
|
+
* A message at level L is emitted only when the active level is >= L. So at
|
|
16
|
+
* `warn`, `warn`/`error` emit but `info`/`debug` are suppressed; at `silent`
|
|
17
|
+
* nothing is emitted at all. Each level routes to its matching `console`
|
|
18
|
+
* method, so existing stderr/stdout semantics are preserved when enabled.
|
|
19
|
+
*/
|
|
20
|
+
/** The set of recognized log levels, ordered from least to most verbose. */
|
|
21
|
+
export type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
|
|
22
|
+
/** Set the active log level (for hosts and tests). */
|
|
23
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
24
|
+
/** Get the active log level. */
|
|
25
|
+
export declare function getLogLevel(): LogLevel;
|
|
26
|
+
/**
|
|
27
|
+
* The shared leveled logger. Each method emits to the matching `console` method
|
|
28
|
+
* ONLY when the active level permits; otherwise it is a no-op.
|
|
29
|
+
*/
|
|
30
|
+
export declare const logger: {
|
|
31
|
+
debug(message?: unknown, ...args: unknown[]): void;
|
|
32
|
+
info(message?: unknown, ...args: unknown[]): void;
|
|
33
|
+
warn(message?: unknown, ...args: unknown[]): void;
|
|
34
|
+
error(message?: unknown, ...args: unknown[]): void;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,4EAA4E;AAC5E,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAqBtE,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAEjD;AAED,gCAAgC;AAChC,wBAAgB,WAAW,IAAI,QAAQ,CAEtC;AAOD;;;GAGG;AACH,eAAO,MAAM,MAAM;oBACD,OAAO,WAAW,OAAO,EAAE,GAAG,IAAI;mBAGnC,OAAO,WAAW,OAAO,EAAE,GAAG,IAAI;mBAGlC,OAAO,WAAW,OAAO,EAAE,GAAG,IAAI;oBAGjC,OAAO,WAAW,OAAO,EAAE,GAAG,IAAI;CAGnD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `historyOutputFormatter` — the single, pure rendering function that turns a
|
|
3
|
+
* {@link Conversation} into one of 17 output shapes.
|
|
4
|
+
*
|
|
5
|
+
* Every swarm orchestrator funnels its final return through this function so
|
|
6
|
+
* the `output_type` contract is honored uniformly. It is a **total function**:
|
|
7
|
+
* the switch handles all 17 named modes plus a default fall-through (which
|
|
8
|
+
* mirrors `"list"`), so no mode falls through to an error for a value in the
|
|
9
|
+
* {@link HistoryOutputType} union.
|
|
10
|
+
*
|
|
11
|
+
* Modes (17): list · dict · dictionary · string · str · final · last · json ·
|
|
12
|
+
* all · yaml · xml · dict-all-except-first · str-all-except-first · basemodel ·
|
|
13
|
+
* dict-final · list-final.
|
|
14
|
+
*/
|
|
15
|
+
import type { Conversation } from "./conversation";
|
|
16
|
+
/** The closed union of output modes a swarm may request. */
|
|
17
|
+
export type HistoryOutputType = "list" | "dict" | "dictionary" | "string" | "str" | "final" | "last" | "json" | "all" | "yaml" | "xml" | "dict-all-except-first" | "str-all-except-first" | "basemodel" | "dict-final" | "list-final";
|
|
18
|
+
/** Alias of {@link HistoryOutputType}. */
|
|
19
|
+
export type OutputType = HistoryOutputType;
|
|
20
|
+
/**
|
|
21
|
+
* Render `conversation` into the shape named by `type`.
|
|
22
|
+
*
|
|
23
|
+
* Returns a varied type by design (string | array | object | tuple) to match
|
|
24
|
+
* the swarms `output_type` contract. The caller knows which shape it asked for.
|
|
25
|
+
*/
|
|
26
|
+
export declare function historyOutputFormatter(conversation: Conversation, type?: HistoryOutputType): unknown;
|
|
27
|
+
//# sourceMappingURL=output-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-formatter.d.ts","sourceRoot":"","sources":["../src/output-formatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,4DAA4D;AAC5D,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,MAAM,GACN,YAAY,GACZ,QAAQ,GACR,KAAK,GACL,OAAO,GACP,MAAM,GACN,MAAM,GACN,KAAK,GACL,MAAM,GACN,KAAK,GACL,uBAAuB,GACvB,sBAAsB,GACtB,WAAW,GACX,YAAY,GACZ,YAAY,CAAC;AAEjB,0CAA0C;AAC1C,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAiC3C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,YAAY,EAC1B,IAAI,GAAE,iBAA0B,GAC/B,OAAO,CA0CT"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt templates: reusable prompt bodies rendered with shell-style positional
|
|
3
|
+
* argument substitution.
|
|
4
|
+
*
|
|
5
|
+
* A prompt template is a Markdown file whose YAML frontmatter carries metadata
|
|
6
|
+
* (a `description`) and whose body is the template text. Rendering substitutes
|
|
7
|
+
* shell-style placeholders with a list of positional arguments — the mechanism
|
|
8
|
+
* behind parameterised slash-command prompts.
|
|
9
|
+
*
|
|
10
|
+
* This module is a standalone runtime primitive: it does NOT depend on the
|
|
11
|
+
* system-prompt assembly (S1). It reuses {@link parseYamlFrontmatter} for the
|
|
12
|
+
* frontmatter split (see loader.ts) rather than re-implementing it.
|
|
13
|
+
*
|
|
14
|
+
* Supported substitution tokens (see {@link substituteArgs} for exact edge
|
|
15
|
+
* behaviour):
|
|
16
|
+
* - `$1`, `$2`, … `$N` — the 1-based Nth argument (multi-digit indices allowed).
|
|
17
|
+
* `$0` and out-of-range indices render empty.
|
|
18
|
+
* - `$@` / `$ARGUMENTS` — every argument, space-joined.
|
|
19
|
+
* - `${@:N}` / `${@:N:L}` — the array slice starting at the 1-based Nth argument
|
|
20
|
+
* (optionally limited to L items), space-joined.
|
|
21
|
+
*
|
|
22
|
+
* Everything else — a lone `$`, `$word`, the colon-less brace form `${@}` — is
|
|
23
|
+
* left untouched. Substitution is a pure string transform (deterministic; no
|
|
24
|
+
* clock / randomness).
|
|
25
|
+
*/
|
|
26
|
+
/** A reusable prompt template: a named body plus a short description. */
|
|
27
|
+
export interface PromptTemplate {
|
|
28
|
+
/** Identifier — a Markdown template's basename without the `.md` suffix. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Short description: the frontmatter `description`, else a body preview. */
|
|
31
|
+
description: string;
|
|
32
|
+
/** Template body; the text rendered by {@link renderPromptTemplate}. */
|
|
33
|
+
content: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Split an argument string into positional arguments using shell-style single
|
|
37
|
+
* and double quoting.
|
|
38
|
+
*
|
|
39
|
+
* Runs of spaces/tabs separate arguments; single or double quotes group
|
|
40
|
+
* whitespace and are removed from the result. Quotes may open mid-token
|
|
41
|
+
* (`foo"bar baz"` → `foobar baz`). Empty quoted tokens (`""`) contribute no
|
|
42
|
+
* argument.
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseCommandArgs(argsString: string): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Substitute prompt-template placeholders with positional arguments.
|
|
47
|
+
*
|
|
48
|
+
* Order and edge behaviour:
|
|
49
|
+
* 1. `$N` (one or more digits) → the 1-based Nth arg, or `""` when absent (so
|
|
50
|
+
* `$0` and out-of-range indices render empty). A `$` followed by digits in
|
|
51
|
+
* prose (`$5`) is therefore treated as a positional token.
|
|
52
|
+
* 2. `${@:N}` / `${@:N:L}` → the arg slice from the 1-based Nth arg (a start
|
|
53
|
+
* below 1 clamps to the first arg), optionally limited to L items (including
|
|
54
|
+
* `L=0` → empty). A start or length past the end simply yields fewer/no args.
|
|
55
|
+
* The colon-less brace form `${@}` is NOT a token and stays literal.
|
|
56
|
+
* 3. `$ARGUMENTS` and `$@` → every arg space-joined.
|
|
57
|
+
*
|
|
58
|
+
* Anything else (a lone `$`, `$word`) is left untouched.
|
|
59
|
+
*/
|
|
60
|
+
export declare function substituteArgs(content: string, args: string[]): string;
|
|
61
|
+
/**
|
|
62
|
+
* Parse Markdown template content into a {@link PromptTemplate}.
|
|
63
|
+
*
|
|
64
|
+
* The frontmatter is split via {@link parseYamlFrontmatter}; the trimmed body
|
|
65
|
+
* becomes {@link PromptTemplate.content}. The description is the frontmatter
|
|
66
|
+
* `description` when present, otherwise a preview of the first non-blank body
|
|
67
|
+
* line (truncated to 60 chars with an ellipsis). Pure — no filesystem access.
|
|
68
|
+
*/
|
|
69
|
+
export declare function parsePromptTemplate(name: string, content: string): PromptTemplate;
|
|
70
|
+
/**
|
|
71
|
+
* Load a Markdown prompt-template file. The template name is the file's
|
|
72
|
+
* basename without the `.md` suffix; the rest is delegated to
|
|
73
|
+
* {@link parsePromptTemplate}.
|
|
74
|
+
*/
|
|
75
|
+
export declare function loadPromptTemplate(filePath: string): Promise<PromptTemplate>;
|
|
76
|
+
/** Render a prompt template's body against positional arguments. */
|
|
77
|
+
export declare function renderPromptTemplate(template: PromptTemplate, args?: string[]): string;
|
|
78
|
+
//# sourceMappingURL=prompt-templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-templates.d.ts","sourceRoot":"","sources":["../src/prompt-templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,WAAW,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;CACjB;AAKD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAuB7D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBtE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAWjF;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAIlF;AAED,oEAAoE;AACpE,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,cAAc,EAAE,IAAI,GAAE,MAAM,EAAO,GAAG,MAAM,CAE1F"}
|
package/dist/result.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `Result` is the explicit success-or-failure value AP3X uses instead of
|
|
3
|
+
* throwing for *expected* failures. The loop, the filesystem layer and the
|
|
4
|
+
* shell layer all return `Result` so callers handle errors as data.
|
|
5
|
+
*/
|
|
6
|
+
export type Result<TValue, TError> = {
|
|
7
|
+
readonly ok: true;
|
|
8
|
+
readonly value: TValue;
|
|
9
|
+
} | {
|
|
10
|
+
readonly ok: false;
|
|
11
|
+
readonly error: TError;
|
|
12
|
+
};
|
|
13
|
+
/** Construct a successful {@link Result}. */
|
|
14
|
+
export declare function ok<TValue, TError = never>(value: TValue): Result<TValue, TError>;
|
|
15
|
+
/** Construct a failed {@link Result}. */
|
|
16
|
+
export declare function err<TError, TValue = never>(error: TError): Result<TValue, TError>;
|
|
17
|
+
/** Unwrap a {@link Result}, throwing the error if it failed. For tests and adapter seams. */
|
|
18
|
+
export declare function getOrThrow<TValue, TError>(result: Result<TValue, TError>): TValue;
|
|
19
|
+
/**
|
|
20
|
+
* Unwrap a {@link Result}, returning `undefined` on failure. Constrained to
|
|
21
|
+
* object values so primitive falsy successes are never confused with failure.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getOrUndefined<TValue extends object, TError>(result: Result<TValue, TError>): TValue | undefined;
|
|
24
|
+
/** Coerce any thrown value into an `Error` so it can be used as a typed cause. */
|
|
25
|
+
export declare function toError(value: unknown): Error;
|
|
26
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAC7B;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,6CAA6C;AAC7C,wBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEhF;AAED,yCAAyC;AACzC,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEjF;AAED,6FAA6F;AAC7F,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAGjF;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,MAAM,EAAE,MAAM,EAC1D,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,MAAM,GAAG,SAAS,CAEpB;AAED,kFAAkF;AAClF,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAQ7C"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe serialization + state persistence for orchestration structures.
|
|
3
|
+
*
|
|
4
|
+
* Two collaborators:
|
|
5
|
+
*
|
|
6
|
+
* - {@link serializeState} / {@link SerializableMixin} — a best-effort,
|
|
7
|
+
* defensive object-to-dict serializer. Callables become `{name, doc}`
|
|
8
|
+
* descriptors; objects exposing `toDict()` recurse; JSON-serializable values
|
|
9
|
+
* pass through; everything else becomes a `<Non-serializable: Type>` marker.
|
|
10
|
+
* An exclusion list lets subclasses skip sensitive/heavy fields.
|
|
11
|
+
*
|
|
12
|
+
* - {@link SafeStateManager} — saves/loads only *safe* (JSON-round-trippable)
|
|
13
|
+
* fields of an object to disk, preserving live class-instance fields across a
|
|
14
|
+
* load (they are never overwritten by the loaded state). Saves are atomic
|
|
15
|
+
* (temp file + backup + rename) — a partial write never clobbers a good file.
|
|
16
|
+
*/
|
|
17
|
+
/** A callable serialized to a name/doc descriptor. */
|
|
18
|
+
export interface CallableDescriptor {
|
|
19
|
+
name: string;
|
|
20
|
+
doc: string | null;
|
|
21
|
+
}
|
|
22
|
+
/** Anything exposing a `toDict()` method participates in nested serialization. */
|
|
23
|
+
export interface HasToDict {
|
|
24
|
+
toDict(): Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/** Serialize a single attribute value defensively (see module docs). */
|
|
27
|
+
export declare function serializeAttr(value: unknown): unknown;
|
|
28
|
+
/**
|
|
29
|
+
* Serialize an object's own enumerable fields to a plain dictionary, skipping
|
|
30
|
+
* any field listed in `exclude`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function serializeState(obj: Record<string, unknown>, exclude?: ReadonlyArray<string>): Record<string, unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Mixin-equivalent base providing a defensive `toDict()`.
|
|
35
|
+
*
|
|
36
|
+
* Subclasses set `_toDictExclude` to skip fields. Extend this class to inherit
|
|
37
|
+
* `toDict`.
|
|
38
|
+
*/
|
|
39
|
+
export declare class SerializableMixin {
|
|
40
|
+
/** Field names to omit from `toDict()`. Override in subclasses. */
|
|
41
|
+
protected _toDictExclude: ReadonlyArray<string>;
|
|
42
|
+
/** Serialize this instance's own enumerable fields to a plain dictionary. */
|
|
43
|
+
toDict(): Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Is `value` a "safe" type — directly JSON-round-trippable without losing
|
|
47
|
+
* identity (primitives, null, arrays/dicts of safe values)?
|
|
48
|
+
*/
|
|
49
|
+
export declare function isSafeType(value: unknown): boolean;
|
|
50
|
+
/** Is `value` a live class instance (not a plain object/primitive)? */
|
|
51
|
+
export declare function isClassInstance(value: unknown): boolean;
|
|
52
|
+
/** Collect the subset of an object's own fields that are safe to persist. */
|
|
53
|
+
export declare function createStateDict(obj: Record<string, unknown>): Record<string, unknown>;
|
|
54
|
+
/** Collect the object's own fields that are live class instances. */
|
|
55
|
+
export declare function preserveInstances(obj: Record<string, unknown>): Record<string, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Saves and loads object state to/from JSON on disk, automatically handling
|
|
58
|
+
* complex/live-instance fields (they are preserved across a load, never
|
|
59
|
+
* clobbered by persisted data).
|
|
60
|
+
*/
|
|
61
|
+
export declare const SafeStateManager: {
|
|
62
|
+
/**
|
|
63
|
+
* Atomically save the object's safe state to `filePath`.
|
|
64
|
+
*
|
|
65
|
+
* Writes a temp file, backs up any existing file, then renames the temp into
|
|
66
|
+
* place so a crash mid-write never corrupts the target.
|
|
67
|
+
*/
|
|
68
|
+
saveState(obj: Record<string, unknown>, filePath: string): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Load persisted safe state into `obj`, preserving any live class-instance
|
|
71
|
+
* fields the object already holds.
|
|
72
|
+
*/
|
|
73
|
+
loadState(obj: Record<string, unknown>, filePath: string): Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,sDAAsD;AACtD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,kFAAkF;AAClF,MAAM,WAAW,SAAS;IACxB,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAmBD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAcrD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,OAAO,GAAE,aAAa,CAAC,MAAM,CAAM,GAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQzB;AAED;;;;;GAKG;AACH,qBAAa,iBAAiB;IAC5B,mEAAmE;IACnE,SAAS,CAAC,cAAc,EAAE,aAAa,CAAC,MAAM,CAAC,CAAM;IAErD,6EAA6E;IAC7E,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAGlC;AAID;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAalD;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMvD;AAED,6EAA6E;AAC7E,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOrF;AAED,qEAAqE;AACrE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOvF;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;IAC3B;;;;;OAKG;mBACkB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB9E;;;OAGG;mBACkB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAqB/E,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type JsonlFile, Session } from "./session";
|
|
2
|
+
/**
|
|
3
|
+
* A filesystem-backed {@link JsonlFile}: appends and reads lines to a real file
|
|
4
|
+
* on disk. Mirrors {@link StringJsonlFile}'s method contract (the sync model the
|
|
5
|
+
* session storage already uses) but persists via `node:fs`. Parent directories
|
|
6
|
+
* are created on first append.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FileJsonlFile implements JsonlFile {
|
|
9
|
+
private readonly path;
|
|
10
|
+
private ensuredDir;
|
|
11
|
+
constructor(path: string);
|
|
12
|
+
/** Read the entire file, or "" when it does not exist yet. */
|
|
13
|
+
read(): string;
|
|
14
|
+
/** Append a line (the caller supplies the trailing newline). */
|
|
15
|
+
append(line: string): void;
|
|
16
|
+
}
|
|
17
|
+
/** Options for creating (or forking into) a new persisted session. */
|
|
18
|
+
export interface SessionCreateOptions {
|
|
19
|
+
/** Reuse a specific session id instead of minting one. */
|
|
20
|
+
id?: string;
|
|
21
|
+
/** Working directory recorded in the session header. Defaults to `process.cwd()`. */
|
|
22
|
+
cwd?: string;
|
|
23
|
+
/** Records the session this one descends from. */
|
|
24
|
+
parentSessionId?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Options selecting the fork point within a source session. */
|
|
27
|
+
export interface SessionForkOptions extends SessionCreateOptions {
|
|
28
|
+
/** Fork up to this entry. When omitted the whole session is copied. */
|
|
29
|
+
entryId?: string;
|
|
30
|
+
/**
|
|
31
|
+
* `"at"` keeps `entryId` on the new branch; `"before"` (the default) stops
|
|
32
|
+
* just before it — in which case `entryId` must be a user message, so the
|
|
33
|
+
* fork begins fresh from that user turn's parent.
|
|
34
|
+
*/
|
|
35
|
+
position?: "before" | "at";
|
|
36
|
+
}
|
|
37
|
+
/** Per-session listing metadata surfaced by {@link SessionRepo.list}. */
|
|
38
|
+
export interface SessionListEntry {
|
|
39
|
+
id: string;
|
|
40
|
+
/** Absolute path of the backing `.jsonl` file. */
|
|
41
|
+
path: string;
|
|
42
|
+
cwd: string;
|
|
43
|
+
/** Current session name, when one was recorded along the branch. */
|
|
44
|
+
name?: string;
|
|
45
|
+
/** Id of the session this one was forked from, when applicable. */
|
|
46
|
+
parentSessionId?: string;
|
|
47
|
+
/** Header timestamp (ms since epoch) — when the session was created. */
|
|
48
|
+
createdAt: number;
|
|
49
|
+
/** File mtime (ms since epoch) — when the session was last written. */
|
|
50
|
+
updatedAt: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A store of persisted sessions: create / open / list / delete, plus `fork`
|
|
54
|
+
* (branch a session into a new independent id that shares history up to a fork
|
|
55
|
+
* point). Faithfully shaped from the pi `SessionRepo`, AP3X-native (sessions are
|
|
56
|
+
* addressed by id, matching the one-file-per-id layout).
|
|
57
|
+
*/
|
|
58
|
+
export interface SessionRepo {
|
|
59
|
+
/** Mint a new session (id + backing file) and return it. */
|
|
60
|
+
create(options?: SessionCreateOptions): Session;
|
|
61
|
+
/** Load an existing session by id. Throws `not_found` when it is absent. */
|
|
62
|
+
open(id: string): Session;
|
|
63
|
+
/** List persisted sessions, newest first. Tolerates corrupt files. */
|
|
64
|
+
list(): SessionListEntry[];
|
|
65
|
+
/** Remove a session's backing file. A missing id is a no-op. */
|
|
66
|
+
delete(id: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Fork a session into a new independent id whose file shares history up to the
|
|
69
|
+
* fork point. Mutating either side afterwards never affects the other.
|
|
70
|
+
*/
|
|
71
|
+
fork(id: string, options?: SessionForkOptions): Session;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A {@link SessionRepo} storing one `.jsonl` file per session id under a root
|
|
75
|
+
* directory (default `~/.ap3x/sessions`; injectable so tests use a temp dir).
|
|
76
|
+
*/
|
|
77
|
+
export declare class JsonlSessionRepo implements SessionRepo {
|
|
78
|
+
private readonly root;
|
|
79
|
+
constructor(options?: {
|
|
80
|
+
root?: string;
|
|
81
|
+
});
|
|
82
|
+
private pathFor;
|
|
83
|
+
private fileFor;
|
|
84
|
+
create(options?: SessionCreateOptions): Session;
|
|
85
|
+
open(id: string): Session;
|
|
86
|
+
list(): SessionListEntry[];
|
|
87
|
+
delete(id: string): void;
|
|
88
|
+
fork(id: string, options?: SessionForkOptions): Session;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=session-repo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-repo.d.ts","sourceRoot":"","sources":["../src/session-repo.ts"],"names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