pi-gentic 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/README.md +499 -0
- package/dist/commands.d.ts +93 -0
- package/dist/commands.js +422 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +407 -0
- package/dist/core.d.ts +19 -0
- package/dist/core.js +125 -0
- package/dist/extension.d.ts +2 -0
- package/dist/extension.js +476 -0
- package/dist/orchestrator.d.ts +277 -0
- package/dist/orchestrator.js +633 -0
- package/dist/policy.d.ts +43 -0
- package/dist/policy.js +136 -0
- package/dist/prompt.d.ts +12 -0
- package/dist/prompt.js +226 -0
- package/dist/runs.d.ts +99 -0
- package/dist/runs.js +540 -0
- package/dist/runtime.d.ts +127 -0
- package/dist/runtime.js +360 -0
- package/dist/sessions.d.ts +56 -0
- package/dist/sessions.js +487 -0
- package/dist/ui.d.ts +108 -0
- package/dist/ui.js +957 -0
- package/dist/worktrees.d.ts +1 -0
- package/dist/worktrees.js +86 -0
- package/docs/assets/error-card.png +0 -0
- package/docs/assets/load-agent.png +0 -0
- package/docs/assets/orchestration-tree.png +0 -0
- package/docs/assets/send-background.png +0 -0
- package/docs/assets/send-foreground.png +0 -0
- package/package.json +58 -0
package/dist/policy.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy and active-agent state.
|
|
3
|
+
*
|
|
4
|
+
* A session stores a tiny append-only recipe. This module resolves that recipe
|
|
5
|
+
* against current settings and current resources every time policy is needed.
|
|
6
|
+
*/
|
|
7
|
+
import { applyFilterList, coalesce, isRecord, mergeFilterLayers } from "./core.js";
|
|
8
|
+
const DEFAULT_ACCESS = ["*"];
|
|
9
|
+
/** Combines defaults, the active agent, and runtime overrides into usable policy. */
|
|
10
|
+
export function resolveSessionPolicy({ settings, activeAgent, overrides, allAgents, allTools, allSkills, }) {
|
|
11
|
+
const defaults = settings.agentDefaults ?? {};
|
|
12
|
+
const agentless = settings.agentlessSession ?? {};
|
|
13
|
+
const base = activeAgent ? defaults : agentless;
|
|
14
|
+
const merged = mergeObjects(base, activeAgent ?? {});
|
|
15
|
+
const resolved = mergeObjects(merged, overrides ?? {});
|
|
16
|
+
const agentsFilter = (activeAgent
|
|
17
|
+
? mergeFilterLayers(defaults.agents, activeAgent.agents, overrides?.agents)
|
|
18
|
+
: mergeFilterLayers(agentless.agents, overrides?.agents)) ??
|
|
19
|
+
DEFAULT_ACCESS;
|
|
20
|
+
const toolsFilter = (activeAgent
|
|
21
|
+
? mergeFilterLayers(defaults.tools, activeAgent.tools, overrides?.tools)
|
|
22
|
+
: mergeFilterLayers(agentless.tools, overrides?.tools)) ?? DEFAULT_ACCESS;
|
|
23
|
+
const skillsFilter = (activeAgent
|
|
24
|
+
? mergeFilterLayers(defaults.skills, activeAgent.skills, overrides?.skills)
|
|
25
|
+
: mergeFilterLayers(agentless.skills, overrides?.skills)) ??
|
|
26
|
+
DEFAULT_ACCESS;
|
|
27
|
+
const systemPromptFilesFilter = activeAgent
|
|
28
|
+
? mergeFilterLayers(defaults.systemPromptFiles, activeAgent.systemPromptFiles, overrides?.systemPromptFiles)
|
|
29
|
+
: mergeFilterLayers(agentless.systemPromptFiles, overrides?.systemPromptFiles);
|
|
30
|
+
return {
|
|
31
|
+
agentName: activeAgent?.name,
|
|
32
|
+
description: resolved.description,
|
|
33
|
+
instructions: resolved.instructions,
|
|
34
|
+
model: resolved.model,
|
|
35
|
+
thinking: resolved.thinking,
|
|
36
|
+
theme: resolved.theme,
|
|
37
|
+
maxSubagentDepth: coalesce(resolved.maxSubagentDepth, activeAgent ? 2 : settings.globalMaxSubagentDepth),
|
|
38
|
+
agentsTool: mergeObjects(defaults.agentsTool ?? {}, mergeObjects(activeAgent?.agentsTool ?? {}, overrides?.agentsTool ?? {})),
|
|
39
|
+
systemPromptFiles: systemPromptFilesFilter,
|
|
40
|
+
resources: {
|
|
41
|
+
agents: applyFilterList(allAgents, agentsFilter),
|
|
42
|
+
tools: applyFilterList(allTools, toolsFilter),
|
|
43
|
+
skills: applyFilterList(allSkills, skillsFilter),
|
|
44
|
+
},
|
|
45
|
+
recipe: {
|
|
46
|
+
agentReference: activeAgent?.name,
|
|
47
|
+
overrides: overrides ?? undefined,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Reads the latest pi-gentic state entry from append-only session history. */
|
|
52
|
+
export function getActiveState(sessionManager) {
|
|
53
|
+
const entries = sessionManager.getEntries?.() ?? [];
|
|
54
|
+
for (let index = entries.length - 1; index >= 0; index--) {
|
|
55
|
+
const entry = entries[index];
|
|
56
|
+
if (entry.type === "custom" && entry.customType === "pi-gentic:state") {
|
|
57
|
+
return sanitizeState(entry.data);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { agentName: undefined, overrides: undefined };
|
|
61
|
+
}
|
|
62
|
+
/** Writes a new durable active-agent recipe without mutating older entries. */
|
|
63
|
+
export function appendActiveState(sessionManager, state) {
|
|
64
|
+
sessionManager.appendCustomEntry("pi-gentic:state", sanitizeState(state));
|
|
65
|
+
}
|
|
66
|
+
function sanitizeState(value) {
|
|
67
|
+
if (!value || typeof value !== "object")
|
|
68
|
+
return { agentName: undefined, overrides: undefined };
|
|
69
|
+
return {
|
|
70
|
+
agentName: typeof value.agentName === "string" && value.agentName
|
|
71
|
+
? value.agentName
|
|
72
|
+
: undefined,
|
|
73
|
+
overrides: value.overrides && typeof value.overrides === "object"
|
|
74
|
+
? value.overrides
|
|
75
|
+
: undefined,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function mergeObjects(base, patch) {
|
|
79
|
+
const result = { ...(base ?? {}) };
|
|
80
|
+
for (const [key, value] of Object.entries(patch ?? {})) {
|
|
81
|
+
result[key] =
|
|
82
|
+
isPlainObject(value) && isPlainObject(result[key])
|
|
83
|
+
? mergeObjects(result[key], value)
|
|
84
|
+
: value;
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
function isPlainObject(value) {
|
|
89
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
90
|
+
}
|
|
91
|
+
export const AGENT_CYCLE_SHORTCUT = "f7";
|
|
92
|
+
export function nextAgentName(currentAgentName, agents) {
|
|
93
|
+
const cycle = [undefined, ...agents.map((agent) => agent.name)];
|
|
94
|
+
const index = cycle.findIndex((name) => name === currentAgentName);
|
|
95
|
+
return cycle[index === -1 ? 1 : (index + 1) % cycle.length];
|
|
96
|
+
}
|
|
97
|
+
export function hasPersistedAgentState(sessionManager) {
|
|
98
|
+
return (sessionManager.getEntries?.() ?? []).some((entry) => entry.type === "custom" && entry.customType === "pi-gentic:state");
|
|
99
|
+
}
|
|
100
|
+
export function shouldApplyDefaultAgent(event, sessionManager) {
|
|
101
|
+
return (["new", "startup"].includes(event?.reason) &&
|
|
102
|
+
isBlankSession(sessionManager) &&
|
|
103
|
+
!hasPersistedAgentState(sessionManager));
|
|
104
|
+
}
|
|
105
|
+
function isBlankSession(sessionManager) {
|
|
106
|
+
const context = sessionManager.buildSessionContext?.();
|
|
107
|
+
if (context)
|
|
108
|
+
return (context.messages ?? []).length === 0;
|
|
109
|
+
return !(sessionManager.getEntries?.() ?? []).some((entry) => entry.type === "message" || entry.type === "custom_message");
|
|
110
|
+
}
|
|
111
|
+
export function configuredDefaultAgent(settings) {
|
|
112
|
+
return typeof settings?.defaultAgent === "string" &&
|
|
113
|
+
settings.defaultAgent.trim()
|
|
114
|
+
? settings.defaultAgent.trim()
|
|
115
|
+
: undefined;
|
|
116
|
+
}
|
|
117
|
+
export function activeAgentName(sessionManager) {
|
|
118
|
+
return getActiveState(sessionManager).agentName;
|
|
119
|
+
}
|
|
120
|
+
export function filterAvailableAgents(config, policy) {
|
|
121
|
+
const resources = policy.resources;
|
|
122
|
+
const allowedAgents = Array.isArray(resources?.agents)
|
|
123
|
+
? resources.agents.map(String)
|
|
124
|
+
: [];
|
|
125
|
+
const allowed = new Set(allowedAgents);
|
|
126
|
+
const agents = Array.isArray(config.agents)
|
|
127
|
+
? config.agents.filter(isRecord)
|
|
128
|
+
: [];
|
|
129
|
+
return agents.filter((agent) => allowed.has(String(agent.name)));
|
|
130
|
+
}
|
|
131
|
+
export function assertAvailableAgent(agentName, agents) {
|
|
132
|
+
const agent = agents.find((item) => String(item.name).toLowerCase() === String(agentName ?? "").toLowerCase());
|
|
133
|
+
if (!agent)
|
|
134
|
+
throw new Error(`Unavailable agent "${agentName}". Available agents: ${agents.map((item) => item.name).join(", ") || "none"}.`);
|
|
135
|
+
return agent;
|
|
136
|
+
}
|
package/dist/prompt.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Produces the final prompt Pi will use before an agent run starts. */
|
|
2
|
+
export declare function buildResolvedSystemPrompt({ baseSystemPrompt, config, policy, skillEntries, }: {
|
|
3
|
+
baseSystemPrompt: any;
|
|
4
|
+
config: any;
|
|
5
|
+
policy: any;
|
|
6
|
+
skillEntries: any;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function mergeSkillEntries(primary?: AnyRecord[], secondary?: AnyRecord[]): any[];
|
|
9
|
+
export declare function availableAgentLines(agents: any, allowedNames: any): any;
|
|
10
|
+
/** Extracts native Pi skill metadata so policy can filter it before display. */
|
|
11
|
+
export declare function parseSkillEntries(systemPrompt: any): AnyRecord[];
|
|
12
|
+
export declare function filterSkillPrompt(systemPrompt: any, skillEntries: any, allowedSkills: any): string;
|
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt construction for Pi sessions.
|
|
3
|
+
*
|
|
4
|
+
* Policy decides which agents, skills, and prompt files are visible. This file
|
|
5
|
+
* turns that resolved policy into human-readable system prompt text.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { applyFilterList, isRecord } from "./core.js";
|
|
10
|
+
const AGENT_SYSTEM_PROMPT = "@agent/SYSTEM.md";
|
|
11
|
+
const DELEGATION_PROMPT = "@agent/extensions/pi-gentic/DELEGATION.md";
|
|
12
|
+
/** Produces the final prompt Pi will use before an agent run starts. */
|
|
13
|
+
export function buildResolvedSystemPrompt({ baseSystemPrompt, config, policy, skillEntries, }) {
|
|
14
|
+
const resolvedSkillEntries = mergeSkillEntries(skillEntries, parseSkillEntries(baseSystemPrompt));
|
|
15
|
+
const sources = promptSources({ baseSystemPrompt, config, policy });
|
|
16
|
+
const sections = [
|
|
17
|
+
...sources
|
|
18
|
+
.filter((source) => source.slot === "native")
|
|
19
|
+
.map((source) => source.content),
|
|
20
|
+
policy.instructions,
|
|
21
|
+
...sources
|
|
22
|
+
.filter((source) => source.slot !== "native")
|
|
23
|
+
.map((source) => source.content),
|
|
24
|
+
agentsSection(config, policy),
|
|
25
|
+
namingSection(policy),
|
|
26
|
+
skillsSection(resolvedSkillEntries, policy),
|
|
27
|
+
]
|
|
28
|
+
.map(cleanSection)
|
|
29
|
+
.filter(Boolean);
|
|
30
|
+
return sections.join("\n\n");
|
|
31
|
+
}
|
|
32
|
+
export function mergeSkillEntries(primary = [], secondary = []) {
|
|
33
|
+
const merged = new Map();
|
|
34
|
+
for (const entry of [...primary, ...secondary]) {
|
|
35
|
+
if (!entry?.name || merged.has(entry.name))
|
|
36
|
+
continue;
|
|
37
|
+
merged.set(entry.name, entry);
|
|
38
|
+
}
|
|
39
|
+
return [...merged.values()];
|
|
40
|
+
}
|
|
41
|
+
export function availableAgentLines(agents, allowedNames) {
|
|
42
|
+
const allowed = new Set(allowedNames);
|
|
43
|
+
const lines = agents
|
|
44
|
+
.filter((agent) => allowed.has(agent.name))
|
|
45
|
+
.map((agent) => `- ${agent.name}: ${agent.description ?? ""}`.trim());
|
|
46
|
+
return lines.join("\n") || "none";
|
|
47
|
+
}
|
|
48
|
+
/** Extracts native Pi skill metadata so policy can filter it before display. */
|
|
49
|
+
export function parseSkillEntries(systemPrompt) {
|
|
50
|
+
const entries = [];
|
|
51
|
+
const block = String(systemPrompt ?? "").match(/<available_skills>[\s\S]*?<\/available_skills>/)?.[0];
|
|
52
|
+
if (!block)
|
|
53
|
+
return entries;
|
|
54
|
+
for (const match of block.matchAll(/<skill>[\s\S]*?<\/skill>/g)) {
|
|
55
|
+
const skillBlock = match[0];
|
|
56
|
+
const name = xmlValue(skillBlock, "name");
|
|
57
|
+
if (name)
|
|
58
|
+
entries.push({
|
|
59
|
+
name,
|
|
60
|
+
description: xmlValue(skillBlock, "description") ?? "",
|
|
61
|
+
location: xmlValue(skillBlock, "location") ?? "",
|
|
62
|
+
block: skillBlock,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return entries;
|
|
66
|
+
}
|
|
67
|
+
export function filterSkillPrompt(systemPrompt, skillEntries, allowedSkills) {
|
|
68
|
+
const prompt = removeNativeSkillSection(systemPrompt);
|
|
69
|
+
const skills = readableSkillLines(skillEntries, allowedSkills);
|
|
70
|
+
return skills.length
|
|
71
|
+
? [prompt.trim(), "Available skills", ...skills].filter(Boolean).join("\n")
|
|
72
|
+
: prompt;
|
|
73
|
+
}
|
|
74
|
+
function promptSources({ baseSystemPrompt, config, policy }) {
|
|
75
|
+
const filters = Array.isArray(policy.systemPromptFiles)
|
|
76
|
+
? policy.systemPromptFiles
|
|
77
|
+
: undefined;
|
|
78
|
+
const sources = [
|
|
79
|
+
...nativePromptSources(baseSystemPrompt),
|
|
80
|
+
...delegationSources(config, policy),
|
|
81
|
+
...promptFileSources(config, filters),
|
|
82
|
+
].filter((source) => source.content);
|
|
83
|
+
if (!filters)
|
|
84
|
+
return sources;
|
|
85
|
+
const allowed = new Set(applyFilterList(sources.map((source) => source.id), filters));
|
|
86
|
+
return sources.filter((source) => allowed.has(source.id));
|
|
87
|
+
}
|
|
88
|
+
function nativePromptSources(systemPrompt) {
|
|
89
|
+
const prompt = removeNativeSkillSection(systemPrompt);
|
|
90
|
+
const projectSources = [];
|
|
91
|
+
const withoutProjectInstructions = prompt.replace(/<project_instructions\b([^>]*)>([\s\S]*?)<\/project_instructions>/g, (full, attributes, body) => {
|
|
92
|
+
const sourcePath = attributes.match(/\bpath=["']([^"']+)["']/)?.[1] ?? "AGENTS.md";
|
|
93
|
+
projectSources.push({
|
|
94
|
+
id: sourcePath,
|
|
95
|
+
content: stripXmlTags(body).trim(),
|
|
96
|
+
});
|
|
97
|
+
return "";
|
|
98
|
+
});
|
|
99
|
+
return [
|
|
100
|
+
{
|
|
101
|
+
id: AGENT_SYSTEM_PROMPT,
|
|
102
|
+
slot: "native",
|
|
103
|
+
content: stripXmlTags(withoutProjectInstructions).trim(),
|
|
104
|
+
},
|
|
105
|
+
...projectSources.map((source) => ({ ...source, slot: "native" })),
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
function delegationSources(config, policy) {
|
|
109
|
+
if (!canUseAgentsTool(policy) ||
|
|
110
|
+
(policy.resources?.agents ?? []).length === 0)
|
|
111
|
+
return [];
|
|
112
|
+
return (config.roots ?? [])
|
|
113
|
+
.map((root) => {
|
|
114
|
+
const filePath = path.join(root, "DELEGATION.md");
|
|
115
|
+
return existsSync(filePath)
|
|
116
|
+
? {
|
|
117
|
+
id: DELEGATION_PROMPT,
|
|
118
|
+
slot: "delegation",
|
|
119
|
+
content: readFileSync(filePath, "utf8").trim(),
|
|
120
|
+
}
|
|
121
|
+
: undefined;
|
|
122
|
+
})
|
|
123
|
+
.filter(Boolean);
|
|
124
|
+
}
|
|
125
|
+
function promptFileSources(config, filters) {
|
|
126
|
+
return promptFileRefs(filters)
|
|
127
|
+
.map((filePath) => ({
|
|
128
|
+
id: filePath,
|
|
129
|
+
slot: "file",
|
|
130
|
+
content: readPromptFile(filePath, config),
|
|
131
|
+
}))
|
|
132
|
+
.filter((source) => source.content);
|
|
133
|
+
}
|
|
134
|
+
function promptFileRefs(filters) {
|
|
135
|
+
if (!Array.isArray(filters))
|
|
136
|
+
return [];
|
|
137
|
+
return filters
|
|
138
|
+
.map((entry) => (typeof entry === "string" ? entry.trim() : ""))
|
|
139
|
+
.filter(Boolean)
|
|
140
|
+
.flatMap((entry) => entry.startsWith("+")
|
|
141
|
+
? [entry.slice(1)]
|
|
142
|
+
: entry.startsWith("!") || entry.startsWith("-") || entry === "*"
|
|
143
|
+
? []
|
|
144
|
+
: [entry])
|
|
145
|
+
.filter((entry) => entry && !entry.includes("*") && !entry.includes("?"));
|
|
146
|
+
}
|
|
147
|
+
function agentsSection(config, policy) {
|
|
148
|
+
if (!canUseAgentsTool(policy))
|
|
149
|
+
return "";
|
|
150
|
+
const lines = availableAgentLines(config.agents ?? [], policy.resources?.agents ?? []);
|
|
151
|
+
return lines === "none" ? "" : `Available agents\n${lines}`;
|
|
152
|
+
}
|
|
153
|
+
function namingSection(policy) {
|
|
154
|
+
return canUseAgentsTool(policy)
|
|
155
|
+
? "When generating a session or worktree name, it must be 3 words long max."
|
|
156
|
+
: "";
|
|
157
|
+
}
|
|
158
|
+
function skillsSection(skillEntries, policy) {
|
|
159
|
+
const lines = readableSkillLines(skillEntries, policy.resources?.skills ?? []);
|
|
160
|
+
return lines.length ? ["Available skills", ...lines].join("\n") : "";
|
|
161
|
+
}
|
|
162
|
+
function readableSkillLines(skillEntries, allowedSkills) {
|
|
163
|
+
const allowed = new Set(allowedSkills);
|
|
164
|
+
return skillEntries
|
|
165
|
+
.filter((skill) => allowed.has(skill.name))
|
|
166
|
+
.map((skill) => [
|
|
167
|
+
`- ${skill.name}: ${skill.description}`.trim(),
|
|
168
|
+
skill.location ? ` Path: ${skill.location}` : "",
|
|
169
|
+
]
|
|
170
|
+
.filter(Boolean)
|
|
171
|
+
.join("\n"));
|
|
172
|
+
}
|
|
173
|
+
function canUseAgentsTool(policy) {
|
|
174
|
+
return ((policy.resources?.tools ?? []).includes("agents") &&
|
|
175
|
+
(policy.resources?.agents ?? []).length > 0);
|
|
176
|
+
}
|
|
177
|
+
function readPromptFile(filePath, config) {
|
|
178
|
+
const resolved = resolvePromptFile(filePath, config);
|
|
179
|
+
if (!resolved)
|
|
180
|
+
return "";
|
|
181
|
+
try {
|
|
182
|
+
return readFileSync(resolved, "utf8").trim();
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return "";
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function resolvePromptFile(filePath, config) {
|
|
189
|
+
if (!filePath || typeof filePath !== "string")
|
|
190
|
+
return undefined;
|
|
191
|
+
const candidates = [];
|
|
192
|
+
if (path.isAbsolute(filePath))
|
|
193
|
+
candidates.push(filePath);
|
|
194
|
+
const roots = Array.isArray(config.roots) ? config.roots : [];
|
|
195
|
+
for (const root of roots) {
|
|
196
|
+
if (typeof root === "string")
|
|
197
|
+
candidates.push(path.resolve(root, filePath));
|
|
198
|
+
}
|
|
199
|
+
const activeAgent = config.activeAgent;
|
|
200
|
+
const sourcePath = isRecord(activeAgent) && typeof activeAgent.sourcePath === "string"
|
|
201
|
+
? activeAgent.sourcePath
|
|
202
|
+
: undefined;
|
|
203
|
+
if (sourcePath && !path.isAbsolute(filePath))
|
|
204
|
+
candidates.push(path.resolve(path.dirname(sourcePath.split("#")[0]), filePath));
|
|
205
|
+
candidates.push(path.resolve(filePath));
|
|
206
|
+
return candidates.find((candidate) => existsSync(candidate));
|
|
207
|
+
}
|
|
208
|
+
function removeNativeSkillSection(systemPrompt) {
|
|
209
|
+
return String(systemPrompt ?? "")
|
|
210
|
+
.replace(/\n*The following skills provide specialized instructions for specific tasks\.[\s\S]*?<\/available_skills>/, "")
|
|
211
|
+
.trim();
|
|
212
|
+
}
|
|
213
|
+
function stripXmlTags(text) {
|
|
214
|
+
return String(text ?? "")
|
|
215
|
+
.replace(/<\/?(?:project_context|project_instructions|active-agent|available_skills|skill|name|description|location)(?:\s+[^>]*)?>/g, "")
|
|
216
|
+
.replace(/^[ \t]+$/gm, "")
|
|
217
|
+
.replace(/\n{3,}/g, "\n\n");
|
|
218
|
+
}
|
|
219
|
+
function cleanSection(value) {
|
|
220
|
+
return stripXmlTags(value).trim();
|
|
221
|
+
}
|
|
222
|
+
function xmlValue(block, tag) {
|
|
223
|
+
return block
|
|
224
|
+
.match(new RegExp(`<${tag}>([\\s\\S]*?)<\\/${tag}>`))?.[1]
|
|
225
|
+
?.trim();
|
|
226
|
+
}
|
package/dist/runs.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export declare function abortActor(ctx: any): string;
|
|
2
|
+
export declare function shouldDeferSendCompletion({ async, awaitCompletion, }?: AnyRecord): boolean;
|
|
3
|
+
export declare function sendPendingText({ async, agentName, sessionId, message, details, }: {
|
|
4
|
+
async: any;
|
|
5
|
+
agentName: any;
|
|
6
|
+
sessionId: any;
|
|
7
|
+
message: any;
|
|
8
|
+
details: any;
|
|
9
|
+
}): string;
|
|
10
|
+
export declare function sendConfirmationText(agentName: unknown, sessionId: unknown, message: string, options?: AnyRecord): string;
|
|
11
|
+
export declare function sendStatusText(details?: AnyRecord): string;
|
|
12
|
+
export declare function deliverSendContextToCaller({ pi, ctx, target, message, async, fork, }: {
|
|
13
|
+
pi: any;
|
|
14
|
+
ctx: any;
|
|
15
|
+
target: any;
|
|
16
|
+
message: any;
|
|
17
|
+
async: any;
|
|
18
|
+
fork: any;
|
|
19
|
+
}): void;
|
|
20
|
+
/** Delivers the target answer to the live caller, or persists it for later. */
|
|
21
|
+
export declare function deliverReturnToCaller({ pi, ctx, callerSessionId, callerSessionManager, text, invoke, persist, invokeInactiveCaller, visibleSession, }: {
|
|
22
|
+
pi: any;
|
|
23
|
+
ctx: any;
|
|
24
|
+
callerSessionId: any;
|
|
25
|
+
callerSessionManager: any;
|
|
26
|
+
text: any;
|
|
27
|
+
invoke: any;
|
|
28
|
+
persist: any;
|
|
29
|
+
invokeInactiveCaller: any;
|
|
30
|
+
visibleSession: any;
|
|
31
|
+
}): Promise<string>;
|
|
32
|
+
export declare function deliverToLiveCaller({ pi, ctx, callerSessionId, text, invoke, visibleSession, }: {
|
|
33
|
+
pi: any;
|
|
34
|
+
ctx: any;
|
|
35
|
+
callerSessionId: any;
|
|
36
|
+
text: any;
|
|
37
|
+
invoke: any;
|
|
38
|
+
visibleSession: any;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
delivered: boolean;
|
|
41
|
+
mode?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
delivered: boolean;
|
|
44
|
+
mode: string;
|
|
45
|
+
}>;
|
|
46
|
+
export declare function persistReturnForCaller({ callerSessionManager, text, invoke, persist, }: {
|
|
47
|
+
callerSessionManager: any;
|
|
48
|
+
text: any;
|
|
49
|
+
invoke: any;
|
|
50
|
+
persist: any;
|
|
51
|
+
}): void;
|
|
52
|
+
export declare function sendUserMessageOptions(ctx: any): {
|
|
53
|
+
deliverAs: string;
|
|
54
|
+
};
|
|
55
|
+
export declare function persistSynchronousToolCard(ctx: PiContext, input: AnyRecord, result: AnyRecord, persist?: (sessionManager: PiSessionManager) => void): void;
|
|
56
|
+
export declare function displayTargetAnswerIfVisible({ ctx, target, targetSessionId, text, }: {
|
|
57
|
+
ctx: any;
|
|
58
|
+
target: any;
|
|
59
|
+
targetSessionId: any;
|
|
60
|
+
text: any;
|
|
61
|
+
}): Promise<boolean>;
|
|
62
|
+
export declare function contextStillActive(ctx: any, callerSessionId?: string): boolean;
|
|
63
|
+
/** Tracks assistant and tool activity so cards can update while a run is live. */
|
|
64
|
+
export declare function createSessionActivityMonitor(baseDetails: any, publish: any): {
|
|
65
|
+
readonly activities: any;
|
|
66
|
+
observe(event: any): void;
|
|
67
|
+
finish({ activities }: {
|
|
68
|
+
activities: any;
|
|
69
|
+
}): any;
|
|
70
|
+
stop(status: string, updates?: AnyRecord): any;
|
|
71
|
+
fail(error: any): any;
|
|
72
|
+
};
|
|
73
|
+
export declare function collectSessionActivities(session: any): any;
|
|
74
|
+
export declare function mergeActivities(...activityLists: unknown[][]): AnyRecord[];
|
|
75
|
+
export declare function lastRuntimeActivities(runtime: any): any;
|
|
76
|
+
export declare function latestActivityLines(runtime: any, count?: number): any;
|
|
77
|
+
export declare function formatActivityLine(activity: any): string;
|
|
78
|
+
/** Converts the target session transcript into the result returned to the caller. */
|
|
79
|
+
export declare function sessionRunOutcome(runtime: AnyRecord, { request, error }?: AnyRecord): {
|
|
80
|
+
status: string;
|
|
81
|
+
text: string;
|
|
82
|
+
};
|
|
83
|
+
export declare function sessionOutcomeText(runtime: AnyRecord, kind: string, { request, error }?: AnyRecord): string;
|
|
84
|
+
/** Summarizes one runtime for status cards and tool responses. */
|
|
85
|
+
export declare function sessionStatus(runtime: any): {
|
|
86
|
+
text: string;
|
|
87
|
+
sessionId: any;
|
|
88
|
+
agentName: any;
|
|
89
|
+
running: boolean;
|
|
90
|
+
state: string;
|
|
91
|
+
pendingMessages: number;
|
|
92
|
+
pendingText: string;
|
|
93
|
+
inactiveMs: number;
|
|
94
|
+
inactiveText: string;
|
|
95
|
+
runningMs: number;
|
|
96
|
+
runningText: string;
|
|
97
|
+
lastActivities: any;
|
|
98
|
+
};
|
|
99
|
+
export declare function formatSessionStatus(status: any): string;
|