memeloop 0.0.1 → 0.1.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 +63 -0
- package/dist/browser.cjs +1413 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +3066 -0
- package/dist/browser.d.ts +3066 -0
- package/dist/browser.js +43 -0
- package/dist/chunk-2C6BJZI3.js +382 -0
- package/dist/chunk-2C6BJZI3.js.map +1 -0
- package/dist/chunk-426CJUZP.js +630 -0
- package/dist/chunk-426CJUZP.js.map +1 -0
- package/dist/chunk-7ZDTB4VZ.js +63 -0
- package/dist/chunk-7ZDTB4VZ.js.map +1 -0
- package/dist/chunk-AZFYDWIN.js +98 -0
- package/dist/chunk-AZFYDWIN.js.map +1 -0
- package/dist/chunk-BGPU4RR7.js +367 -0
- package/dist/chunk-BGPU4RR7.js.map +1 -0
- package/dist/chunk-CCEFAOSH.js +496 -0
- package/dist/chunk-CCEFAOSH.js.map +1 -0
- package/dist/chunk-FWSY5HOA.js +63 -0
- package/dist/chunk-FWSY5HOA.js.map +1 -0
- package/dist/chunk-GYIOMQMY.js +8726 -0
- package/dist/chunk-GYIOMQMY.js.map +1 -0
- package/dist/chunk-K6P63KD4.js +68 -0
- package/dist/chunk-K6P63KD4.js.map +1 -0
- package/dist/chunk-KFS2EJT6.js +42 -0
- package/dist/chunk-KFS2EJT6.js.map +1 -0
- package/dist/chunk-MAJWHAKR.js +3637 -0
- package/dist/chunk-MAJWHAKR.js.map +1 -0
- package/dist/chunk-MRKY4HGF.js +205 -0
- package/dist/chunk-MRKY4HGF.js.map +1 -0
- package/dist/chunk-T7FSXWFR.js +2744 -0
- package/dist/chunk-T7FSXWFR.js.map +1 -0
- package/dist/chunk-VZKQX5PP.js +1 -0
- package/dist/chunk-VZKQX5PP.js.map +1 -0
- package/dist/chunk-WAI6BODI.js +175 -0
- package/dist/chunk-WAI6BODI.js.map +1 -0
- package/dist/chunk-YMNXDNDW.js +798 -0
- package/dist/chunk-YMNXDNDW.js.map +1 -0
- package/dist/conversation.cjs +208 -0
- package/dist/conversation.cjs.map +1 -0
- package/dist/conversation.d.cts +100 -0
- package/dist/conversation.d.ts +100 -0
- package/dist/conversation.js +21 -0
- package/dist/conversation.js.map +1 -0
- package/dist/device-network-portable.cjs +702 -0
- package/dist/device-network-portable.cjs.map +1 -0
- package/dist/device-network-portable.d.cts +110 -0
- package/dist/device-network-portable.d.ts +110 -0
- package/dist/device-network-portable.js +53 -0
- package/dist/device-network-portable.js.map +1 -0
- package/dist/device-network.cjs +906 -0
- package/dist/device-network.cjs.map +1 -0
- package/dist/device-network.d.cts +6 -0
- package/dist/device-network.d.ts +6 -0
- package/dist/device-network.js +59 -0
- package/dist/device-network.js.map +1 -0
- package/dist/fetchProvider-WWnWnQFP.d.ts +91 -0
- package/dist/fetchProvider-toTHy5Nu.d.cts +91 -0
- package/dist/index.cjs +28051 -5459
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -1320
- package/dist/index.d.ts +94 -1320
- package/dist/index.js +10616 -2420
- package/dist/index.js.map +1 -1
- package/dist/interface-IrKBFtL1.d.cts +493 -0
- package/dist/interface-IrKBFtL1.d.ts +493 -0
- package/dist/llm-providers.cjs +43 -8
- package/dist/llm-providers.cjs.map +1 -1
- package/dist/llm-providers.d.cts +2 -1
- package/dist/llm-providers.d.ts +2 -1
- package/dist/llm-providers.js +4 -2
- package/dist/llm-providers.js.map +1 -1
- package/dist/loop-api.cjs +5227 -2010
- package/dist/loop-api.cjs.map +1 -1
- package/dist/loop-api.d.cts +11 -5
- package/dist/loop-api.d.ts +11 -5
- package/dist/loop-api.js +86 -49
- package/dist/mobile.cjs +2711 -0
- package/dist/mobile.cjs.map +1 -0
- package/dist/mobile.d.cts +6 -0
- package/dist/mobile.d.ts +6 -0
- package/dist/mobile.js +22 -0
- package/dist/mobile.js.map +1 -0
- package/dist/orchestration-portable-BHB_YrNN.d.ts +2192 -0
- package/dist/orchestration-portable-mvYBvGBb.d.cts +2192 -0
- package/dist/orchestration-portable.cjs +9553 -0
- package/dist/orchestration-portable.cjs.map +1 -0
- package/dist/orchestration-portable.d.cts +5 -0
- package/dist/orchestration-portable.d.ts +5 -0
- package/dist/orchestration-portable.js +290 -0
- package/dist/orchestration-portable.js.map +1 -0
- package/dist/pairingInvite-BXPWY3aM.d.cts +149 -0
- package/dist/pairingInvite-Cuz0wuq9.d.ts +149 -0
- package/dist/promptConcat-0WNFTg4l.d.ts +516 -0
- package/dist/promptConcat-D6wr5V-V.d.cts +516 -0
- package/dist/providerRegistry-Bi6pAvSj.d.ts +86 -0
- package/dist/providerRegistry-CPsktuiX.d.cts +86 -0
- package/dist/registry-D0kbxksn.d.cts +393 -0
- package/dist/registry-DDbvhlhs.d.ts +393 -0
- package/dist/remoteClient-B_spK019.d.ts +87 -0
- package/dist/remoteClient-CBggnRy3.d.cts +87 -0
- package/dist/runtime-PGWR6FIV.js +18 -0
- package/dist/runtime-PGWR6FIV.js.map +1 -0
- package/dist/scriptDeploymentPipeline-CXJcC82H.d.ts +2464 -0
- package/dist/scriptDeploymentPipeline-yG1ZhVVI.d.cts +2464 -0
- package/dist/syncCloudDevices-BEqwgrhD.d.ts +49 -0
- package/dist/syncCloudDevices-Ds_Kcgrv.d.cts +49 -0
- package/dist/types-7pYti-k9.d.cts +255 -0
- package/dist/types-CdFVSntj.d.ts +255 -0
- package/package.json +110 -35
- package/dist/anthropic.cjs +0 -72
- package/dist/anthropic.cjs.map +0 -1
- package/dist/anthropic.d.cts +0 -21
- package/dist/anthropic.d.ts +0 -21
- package/dist/anthropic.js +0 -21
- package/dist/anthropic.js.map +0 -1
- package/dist/azure.cjs +0 -72
- package/dist/azure.cjs.map +0 -1
- package/dist/azure.d.cts +0 -21
- package/dist/azure.d.ts +0 -21
- package/dist/azure.js +0 -21
- package/dist/azure.js.map +0 -1
- package/dist/chunk-3CN7DFBL.js +0 -4894
- package/dist/chunk-3CN7DFBL.js.map +0 -1
- package/dist/chunk-4AZ4D7U5.js +0 -32
- package/dist/chunk-4AZ4D7U5.js.map +0 -1
- package/dist/chunk-6ON4XSOV.js +0 -63
- package/dist/chunk-6ON4XSOV.js.map +0 -1
- package/dist/chunk-DJQNGIXX.js +0 -4793
- package/dist/chunk-DJQNGIXX.js.map +0 -1
- package/dist/chunk-FKQP6AOQ.js +0 -32
- package/dist/chunk-FKQP6AOQ.js.map +0 -1
- package/dist/chunk-OVJ7JJBA.js +0 -35
- package/dist/chunk-OVJ7JJBA.js.map +0 -1
- package/dist/chunk-P4UZ7IXC.js +0 -42
- package/dist/chunk-YHJ2AEFR.js +0 -4933
- package/dist/chunk-YHJ2AEFR.js.map +0 -1
- package/dist/chunk-YVK7RYRO.js +0 -4973
- package/dist/chunk-YVK7RYRO.js.map +0 -1
- package/dist/code-assistant.json +0 -114
- package/dist/cohere.cjs +0 -72
- package/dist/cohere.cjs.map +0 -1
- package/dist/cohere.d.cts +0 -21
- package/dist/cohere.d.ts +0 -21
- package/dist/cohere.js +0 -21
- package/dist/cohere.js.map +0 -1
- package/dist/deepseek.cjs +0 -72
- package/dist/deepseek.cjs.map +0 -1
- package/dist/deepseek.d.cts +0 -21
- package/dist/deepseek.d.ts +0 -21
- package/dist/deepseek.js +0 -21
- package/dist/deepseek.js.map +0 -1
- package/dist/dist-65U7OYRG.js +0 -1257
- package/dist/dist-65U7OYRG.js.map +0 -1
- package/dist/fetchProvider-Cu4WkU5O.d.cts +0 -819
- package/dist/fetchProvider-Cu4WkU5O.d.ts +0 -819
- package/dist/frontend-ui-ux.json +0 -105
- package/dist/general-assistant.json +0 -95
- package/dist/git-master.json +0 -51
- package/dist/google-vertex.cjs +0 -72
- package/dist/google-vertex.cjs.map +0 -1
- package/dist/google-vertex.d.cts +0 -21
- package/dist/google-vertex.d.ts +0 -21
- package/dist/google-vertex.js +0 -21
- package/dist/google-vertex.js.map +0 -1
- package/dist/google.cjs +0 -72
- package/dist/google.cjs.map +0 -1
- package/dist/google.d.cts +0 -21
- package/dist/google.d.ts +0 -21
- package/dist/google.js +0 -21
- package/dist/google.js.map +0 -1
- package/dist/groq.cjs +0 -72
- package/dist/groq.cjs.map +0 -1
- package/dist/groq.d.cts +0 -21
- package/dist/groq.d.ts +0 -21
- package/dist/groq.js +0 -21
- package/dist/groq.js.map +0 -1
- package/dist/index.d.mts +0 -3203
- package/dist/index.mjs +0 -7064
- package/dist/index.mjs.map +0 -1
- package/dist/mistral.cjs +0 -72
- package/dist/mistral.cjs.map +0 -1
- package/dist/mistral.d.cts +0 -21
- package/dist/mistral.d.ts +0 -21
- package/dist/mistral.js +0 -21
- package/dist/mistral.js.map +0 -1
- package/dist/multipart-parser-EJCXIUHC.js +0 -372
- package/dist/multipart-parser-EJCXIUHC.js.map +0 -1
- package/dist/openai.cjs +0 -72
- package/dist/openai.cjs.map +0 -1
- package/dist/openai.d.cts +0 -21
- package/dist/openai.d.ts +0 -21
- package/dist/openai.js +0 -21
- package/dist/openai.js.map +0 -1
- package/dist/perplexity.cjs +0 -72
- package/dist/perplexity.cjs.map +0 -1
- package/dist/perplexity.d.cts +0 -21
- package/dist/perplexity.d.ts +0 -21
- package/dist/perplexity.js +0 -21
- package/dist/perplexity.js.map +0 -1
- package/dist/playwright.json +0 -52
- package/dist/promptConcat-BJdazTg5.d.cts +0 -1832
- package/dist/promptConcat-BJdazTg5.d.ts +0 -1832
- package/dist/promptConcat-CAkpni_8.d.cts +0 -1834
- package/dist/promptConcat-CAkpni_8.d.ts +0 -1834
- package/dist/promptConcat-CfH5-GAE.d.cts +0 -1036
- package/dist/promptConcat-ChcAZOOL.d.ts +0 -1036
- package/dist/promptConcat-G5TnJVRy.d.cts +0 -1800
- package/dist/promptConcat-G5TnJVRy.d.ts +0 -1800
- package/dist/promptConcat-L72eowzp.d.ts +0 -1090
- package/dist/promptConcat-eLHdN7K8.d.cts +0 -1090
- package/dist/src-VTSXKG72.js +0 -1409
- package/dist/src-VTSXKG72.js.map +0 -1
- package/dist/togetherai.cjs +0 -72
- package/dist/togetherai.cjs.map +0 -1
- package/dist/togetherai.d.cts +0 -21
- package/dist/togetherai.d.ts +0 -21
- package/dist/togetherai.js +0 -21
- package/dist/togetherai.js.map +0 -1
- package/dist/types-B0Jm2l38.d.cts +0 -767
- package/dist/types-B0Jm2l38.d.ts +0 -767
- package/dist/xai.cjs +0 -72
- package/dist/xai.cjs.map +0 -1
- package/dist/xai.d.cts +0 -21
- package/dist/xai.d.ts +0 -21
- package/dist/xai.js +0 -21
- package/dist/xai.js.map +0 -1
- /package/dist/{chunk-P4UZ7IXC.js.map → browser.js.map} +0 -0
|
@@ -1,1090 +0,0 @@
|
|
|
1
|
-
import { A as AgentDefinition, y as AgentInstanceLatestStatus, b as AgentFrameworkConfig, x as AgentInstanceModel, R as ChatRole, a as ChatMessage, a8 as LoopProfileScriptReference, F as AgentLoopScriptPolicy, H as AgentLoopStep, j as AgentLoopInput, a5 as LoopProfile, E as AgentLoopRuntime, k as AgentLoopGenerator, B as AgentLoopDefinition, a0 as ILLMProvider, i as AgentFrameworkContext, z as AgentInstanceState, a4 as LoopPlugin, a6 as LoopProfilePluginEntry, P as PromptConcatTool, ac as PromptNode, J as AgentPromptDescription } from './types-B0Jm2l38.cjs';
|
|
2
|
-
import { LanguageModelV1 } from 'ai';
|
|
3
|
-
|
|
4
|
-
declare const BUILTIN_AGENT_AGENT_LOOP_QUALITY_GATE_SCRIPT_ID = "builtin:agent-agent-loop/quality-gate";
|
|
5
|
-
declare const builtinAgentAgentLoopSources: Readonly<Record<string, string>>;
|
|
6
|
-
declare function getBuiltinAgentAgentLoopSource(id: string): string | undefined;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Domain factories for creating canonical ChatMessage and AgentInstance objects.
|
|
10
|
-
*
|
|
11
|
-
* These factories ensure that every host (Desktop, Mobile, CLI, Cloud)
|
|
12
|
-
* constructs messages and instances with the same required fields,
|
|
13
|
-
* default values, and clock behavior.
|
|
14
|
-
*
|
|
15
|
-
* Hosts that need a different originNodeId, message ID scheme, or lamport
|
|
16
|
-
* clock source should pass those values explicitly rather than creating
|
|
17
|
-
* their own factory.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Create a canonical ChatMessage with required defaults.
|
|
22
|
-
*
|
|
23
|
-
* @param input.messageId - Unique message identifier. Use nanoid or equivalent.
|
|
24
|
-
* @param input.conversationId - The conversation/agent-instance this message belongs to.
|
|
25
|
-
* @param input.role - Message role (user, assistant, tool, agent, error).
|
|
26
|
-
* @param input.content - Message text content.
|
|
27
|
-
* @param input.originNodeId - Node that originated this message. Core default is "unknown";
|
|
28
|
-
* hosts should pass their own identifier (e.g. "tidgi-desktop", "memeloop-cli").
|
|
29
|
-
* @param input.contentType - MIME type override (default "text/plain").
|
|
30
|
-
* @param input.metadata - Optional metadata map.
|
|
31
|
-
* @param input.duration - Processing duration in ms.
|
|
32
|
-
* @param input.lamportClock - Lamport clock value. Defaults to `Date.now()`.
|
|
33
|
-
* @param input.toolCalls - Tool calls associated with assistant messages.
|
|
34
|
-
* @param input.reasoning_content - Reasoning/thinking content.
|
|
35
|
-
* @param input.hidden - Whether the message is hidden from the UI.
|
|
36
|
-
* @param input.detailRef - Reference to large tool output stored elsewhere.
|
|
37
|
-
*/
|
|
38
|
-
declare function createChatMessage(input: {
|
|
39
|
-
messageId: string;
|
|
40
|
-
conversationId: string;
|
|
41
|
-
role: ChatRole;
|
|
42
|
-
content: string;
|
|
43
|
-
originNodeId?: string;
|
|
44
|
-
contentType?: string;
|
|
45
|
-
metadata?: Record<string, unknown>;
|
|
46
|
-
duration?: number | null;
|
|
47
|
-
lamportClock?: number;
|
|
48
|
-
toolCalls?: ChatMessage['toolCalls'];
|
|
49
|
-
reasoning_content?: string;
|
|
50
|
-
hidden?: boolean;
|
|
51
|
-
attachments?: ChatMessage['attachments'];
|
|
52
|
-
detailRef?: ChatMessage['detailRef'];
|
|
53
|
-
}): ChatMessage;
|
|
54
|
-
/**
|
|
55
|
-
* Create an AgentInstance from an AgentDefinition.
|
|
56
|
-
*
|
|
57
|
-
* The returned instance has an empty message list, a default "completed"
|
|
58
|
-
* status, and copies all definition-level fields as instance defaults.
|
|
59
|
-
*
|
|
60
|
-
* @param definition - The AgentDefinition to base the instance on.
|
|
61
|
-
* @param overrides - Optional overrides for instance-specific fields:
|
|
62
|
-
* - `id`: Instance ID (default: nanoid-equivalent, must be provided by host)
|
|
63
|
-
* - `name`: Display name (default: definition.name)
|
|
64
|
-
* - `status`: Initial status
|
|
65
|
-
* - `volatile`: Whether the instance is ephemeral
|
|
66
|
-
* - `closed`: Whether closed on creation
|
|
67
|
-
* - `isDelegatedAgentRun`, `parentAgentRunId`: Delegated agent relationship
|
|
68
|
-
* - `agentFrameworkConfig`: Per-instance framework config override
|
|
69
|
-
*/
|
|
70
|
-
declare function createAgentInstanceFromDefinition(definition: AgentDefinition, overrides: {
|
|
71
|
-
id: string;
|
|
72
|
-
name?: string;
|
|
73
|
-
status?: AgentInstanceLatestStatus;
|
|
74
|
-
volatile?: boolean;
|
|
75
|
-
closed?: boolean;
|
|
76
|
-
isDelegatedAgentRun?: boolean;
|
|
77
|
-
parentAgentRunId?: string;
|
|
78
|
-
agentFrameworkConfig?: AgentFrameworkConfig;
|
|
79
|
-
}): AgentInstanceModel;
|
|
80
|
-
|
|
81
|
-
type AgentLoopScriptReference = string | LoopProfileScriptReference;
|
|
82
|
-
|
|
83
|
-
type LoadAgentAgentLoopScriptOptions = AgentLoopScriptPolicy;
|
|
84
|
-
type AgentAgentLoopScriptReference = AgentLoopScriptReference;
|
|
85
|
-
declare function loadAgentAgentLoopScript(scriptReference: AgentAgentLoopScriptReference, options?: LoadAgentAgentLoopScriptOptions): Promise<AgentAgentLoopScript>;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* AgentAgent_Loop — a loop that orchestrates child agents.
|
|
89
|
-
*
|
|
90
|
-
* This loop does NOT call the LLM directly. Instead it coordinates child agents:
|
|
91
|
-
* - running a child agent and feeding its result to another child agent (review / verify)
|
|
92
|
-
* - splitting work across multiple parallel child agents
|
|
93
|
-
* - looping back to a child agent with feedback when a reviewer rejects the output
|
|
94
|
-
*
|
|
95
|
-
* The loop script (.mjs) holds the orchestration logic. This file provides the
|
|
96
|
-
* runtime that invokes the script and manages child agent runs.
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Typed API passed to a AgentAgent `.mjs` script.
|
|
101
|
-
*
|
|
102
|
-
* The API is intentionally primitive: scripts decide the workflow shape, role
|
|
103
|
-
* names, approval rules, retry limits, and delivery gates. This runtime only
|
|
104
|
-
* handles child-agent execution, progress events, cancellation, state, and
|
|
105
|
-
* checkpoints.
|
|
106
|
-
*/
|
|
107
|
-
interface AgentAgentLoopScriptArguments {
|
|
108
|
-
/** The parent turn input. `input.message` is the user's original goal. */
|
|
109
|
-
input: AgentLoopInput;
|
|
110
|
-
/** Host/runtime context for advanced integrations. Prefer the typed helpers below when possible. */
|
|
111
|
-
context: AgentAgentLoopContext;
|
|
112
|
-
/** Active profile. Scripts may define their own workflow-specific metadata keys here. */
|
|
113
|
-
profile?: LoopProfile;
|
|
114
|
-
/** Normalized worker agents read from `context.agents` or `profile.metadata.agents`. */
|
|
115
|
-
agents: AgentAgentDescriptor[];
|
|
116
|
-
/**
|
|
117
|
-
* Read raw agent entries from `profile.metadata[key]`; defaults to `agents`.
|
|
118
|
-
* This is deliberately generic so scripts can choose names like `critics`,
|
|
119
|
-
* `builders`, `verifiers`, or any other workflow-specific role.
|
|
120
|
-
*/
|
|
121
|
-
getAgentEntries: (key?: string) => AgentAgentConfigEntry[];
|
|
122
|
-
/** Low-level runtime hooks. Prefer `state`, `checkpoint`, `emit`, and run helpers first. */
|
|
123
|
-
runtime?: Partial<AgentLoopRuntime>;
|
|
124
|
-
/** Run one child agent and collect all yielded steps into a text result. */
|
|
125
|
-
runAgent: (input: AgentAgentRunAgentInput) => Promise<AgentAgentRunAgentResult>;
|
|
126
|
-
/** Run child agents concurrently. Use `runSequential` when order matters. */
|
|
127
|
-
runAgents: (inputs: AgentAgentRunAgentInput[]) => Promise<AgentAgentRunAgentResult[]>;
|
|
128
|
-
/** Run a batch of agents in order, aggregating successful output and failures. */
|
|
129
|
-
runSequential: (input?: AgentAgentBatchRunInput) => Promise<AgentAgentBatchRunResult>;
|
|
130
|
-
/** Run a batch of agents concurrently, aggregating successful output and failures. */
|
|
131
|
-
runParallel: (input?: AgentAgentBatchRunInput) => Promise<AgentAgentBatchRunResult>;
|
|
132
|
-
/** Format a batch result for final delivery or an intermediate report. */
|
|
133
|
-
formatAgentResults: (result: AgentAgentBatchRunResult, options?: AgentAgentFormatResultsOptions) => string;
|
|
134
|
-
/** Emit a formatted batch result as the parent loop's final/user-visible message. */
|
|
135
|
-
finishAgentResults: (result: AgentAgentBatchRunResult, options?: AgentAgentFormatResultsOptions) => void;
|
|
136
|
-
/** Emit a raw loop step upstream. Use sparingly; helpers already emit progress. */
|
|
137
|
-
emit: (step: AgentLoopStep) => void;
|
|
138
|
-
/** Emit a user-visible message or step and end the script's work. */
|
|
139
|
-
finish: (message: string | AgentLoopStep) => void;
|
|
140
|
-
/** True when the host cancelled this parent run. Long-running scripts should check this between phases. */
|
|
141
|
-
isCancelled: () => boolean;
|
|
142
|
-
/** Write an observability event through the host runtime logger. */
|
|
143
|
-
log: (event: string, data?: Record<string, unknown>) => void;
|
|
144
|
-
/** Per-run persistent state scoped by the host runtime. */
|
|
145
|
-
state: AgentLoopRuntime['state'];
|
|
146
|
-
/** Record a resumable milestone for long workflows. */
|
|
147
|
-
checkpoint: AgentLoopRuntime['checkpoint'];
|
|
148
|
-
}
|
|
149
|
-
type AgentAgentScriptContext = AgentAgentLoopScriptArguments;
|
|
150
|
-
type AgentAgentContext = AgentAgentScriptContext;
|
|
151
|
-
interface AgentAgentDescriptor {
|
|
152
|
-
/** Child profile id to run. */
|
|
153
|
-
profileId: string;
|
|
154
|
-
/** Prompt override for this child run. Defaults to the parent input message. */
|
|
155
|
-
prompt?: string;
|
|
156
|
-
/** Conversation id override. Defaults to `${parent}:child:${index}` for batch helpers. */
|
|
157
|
-
conversationId?: string;
|
|
158
|
-
/** Optional human-readable role label, e.g. "implementer" or "reviewer". */
|
|
159
|
-
label?: string;
|
|
160
|
-
[key: string]: unknown;
|
|
161
|
-
}
|
|
162
|
-
type AgentAgentConfigEntry = string | ({
|
|
163
|
-
profileId?: string;
|
|
164
|
-
profile?: string;
|
|
165
|
-
prompt?: string;
|
|
166
|
-
conversationId?: string;
|
|
167
|
-
label?: string;
|
|
168
|
-
} & Record<string, unknown>);
|
|
169
|
-
interface AgentAgentRunAgentInput {
|
|
170
|
-
/** Child profile id. `profile` is accepted as an ergonomic alias for scripts. */
|
|
171
|
-
profileId?: string;
|
|
172
|
-
profile?: string;
|
|
173
|
-
/** Defaults to the parent input message. */
|
|
174
|
-
prompt?: string;
|
|
175
|
-
conversationId?: string;
|
|
176
|
-
label?: string;
|
|
177
|
-
}
|
|
178
|
-
interface AgentAgentRunAgentResult {
|
|
179
|
-
profileId: string;
|
|
180
|
-
conversationId: string;
|
|
181
|
-
steps: AgentLoopStep[];
|
|
182
|
-
text: string;
|
|
183
|
-
}
|
|
184
|
-
interface AgentAgentRunAgentFailure {
|
|
185
|
-
profileId: string;
|
|
186
|
-
conversationId?: string;
|
|
187
|
-
error: string;
|
|
188
|
-
}
|
|
189
|
-
interface AgentAgentBatchRunInput {
|
|
190
|
-
/** Agents to run. Defaults to `ctx.agents`. */
|
|
191
|
-
agents?: AgentAgentConfigEntry[];
|
|
192
|
-
/** Prompt shared by every agent in this batch. Defaults to the parent input message. */
|
|
193
|
-
prompt?: string;
|
|
194
|
-
/** When false, the first child failure rejects the batch. Defaults to true. */
|
|
195
|
-
continueOnError?: boolean;
|
|
196
|
-
}
|
|
197
|
-
interface AgentAgentBatchRunResult {
|
|
198
|
-
results: AgentAgentRunAgentResult[];
|
|
199
|
-
failures: AgentAgentRunAgentFailure[];
|
|
200
|
-
text: string;
|
|
201
|
-
}
|
|
202
|
-
interface AgentAgentFormatResultsOptions {
|
|
203
|
-
emptyMessage?: string;
|
|
204
|
-
failureHeader?: string;
|
|
205
|
-
includeFailureSection?: boolean;
|
|
206
|
-
}
|
|
207
|
-
type AgentAgentLoopScriptResult = AgentLoopGenerator | AgentLoopStep | AgentLoopStep[] | string | undefined;
|
|
208
|
-
type AgentAgentLoopScript = (scriptArguments: AgentAgentLoopScriptArguments) => AgentAgentLoopScriptResult | Promise<AgentAgentLoopScriptResult>;
|
|
209
|
-
interface AgentAgentLoopContext {
|
|
210
|
-
[key: string]: unknown;
|
|
211
|
-
profile?: LoopProfile;
|
|
212
|
-
runtime?: Partial<AgentLoopRuntime>;
|
|
213
|
-
agents?: AgentAgentConfigEntry[];
|
|
214
|
-
script?: AgentAgentLoopScript;
|
|
215
|
-
loadScript?: (script: AgentAgentLoopScriptReference, context: AgentAgentLoopContext) => AgentAgentLoopScript | Promise<AgentAgentLoopScript>;
|
|
216
|
-
scriptPolicy?: LoadAgentAgentLoopScriptOptions;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Create the AgentAgent_Loop definition and register it with the loop registry.
|
|
220
|
-
*/
|
|
221
|
-
declare function createAgentAgentLoopDefinition(): AgentLoopDefinition;
|
|
222
|
-
/** Export loop id for consumers. */
|
|
223
|
-
declare function getAgentAgentLoopId(): string;
|
|
224
|
-
|
|
225
|
-
declare const BUILTIN_AGENT_TOOL_LOOP_DEFAULT_SCRIPT_ID = "builtin:agent-tool-loop/default";
|
|
226
|
-
declare const builtinAgentToolLoopSources: Readonly<Record<string, string>>;
|
|
227
|
-
declare function getBuiltinAgentToolLoopSource(id: string): string | undefined;
|
|
228
|
-
|
|
229
|
-
interface CompactionOptions {
|
|
230
|
-
/** Maximum token count to aim for after compaction (estimated by char count / 3.5). Default: 0 (no limit). */
|
|
231
|
-
maxTokens?: number;
|
|
232
|
-
/** Number of recent message turns (user+assistant pairs) to preserve. Default: 4. */
|
|
233
|
-
recentTurnsToKeep?: number;
|
|
234
|
-
/** Whether to attempt LLM summarization. Falls back to truncation if LLM unavailable or fails. Default: true. */
|
|
235
|
-
useLlmSummary?: boolean;
|
|
236
|
-
/** Optional LLM provider for summarization. */
|
|
237
|
-
llmProvider?: ILLMProvider;
|
|
238
|
-
}
|
|
239
|
-
interface CompactionResult {
|
|
240
|
-
/** Compacted messages (summary + recent turns). */
|
|
241
|
-
messages: ChatMessage[];
|
|
242
|
-
/** True if compaction reduced the message count. */
|
|
243
|
-
compacted: boolean;
|
|
244
|
-
/** Number of messages dropped. */
|
|
245
|
-
droppedCount: number;
|
|
246
|
-
/** Summary text generated or fallback notice. */
|
|
247
|
-
summaryText: string;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Deterministic compaction: keeps recent N turns and replaces older messages
|
|
251
|
-
* with a single summary message.
|
|
252
|
-
*/
|
|
253
|
-
declare function compactMessages(messages: ChatMessage[], options?: Omit<CompactionOptions, 'llmProvider' | 'useLlmSummary'>): CompactionResult;
|
|
254
|
-
/**
|
|
255
|
-
* Checks whether compaction is needed based on message count threshold.
|
|
256
|
-
* @returns true if message count exceeds threshold (default 50).
|
|
257
|
-
*/
|
|
258
|
-
declare function shouldCompact(messages: ChatMessage[], threshold?: number): boolean;
|
|
259
|
-
/**
|
|
260
|
-
* Auto-compact: estimates token usage, and if it exceeds maxTokens,
|
|
261
|
-
* performs compaction to keep the context within bounds.
|
|
262
|
-
*
|
|
263
|
-
* Uses the LLM provider for summarization if available, falling back to
|
|
264
|
-
* simple truncation + turn counting.
|
|
265
|
-
*/
|
|
266
|
-
declare function autoCompact(messages: ChatMessage[], options?: CompactionOptions): Promise<CompactionResult>;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Layered permission system types.
|
|
270
|
-
*
|
|
271
|
-
* Permissions are resolved by merging rule sets from multiple layers
|
|
272
|
-
* (default → agent → user → session), where later layers override earlier ones.
|
|
273
|
-
*/
|
|
274
|
-
/** Permission action for a tool invocation. */
|
|
275
|
-
type PermissionAction = 'allow' | 'deny' | 'ask';
|
|
276
|
-
/** A single permission rule: matches a tool name pattern to an action. */
|
|
277
|
-
interface PermissionRule {
|
|
278
|
-
/** Wildcard-capable pattern, e.g. `"file.*"`, `"shell(rm)"`, `"*"`. */
|
|
279
|
-
toolPattern: string;
|
|
280
|
-
action: PermissionAction;
|
|
281
|
-
}
|
|
282
|
-
/** A set of permission rules belonging to a specific source/layer. */
|
|
283
|
-
interface PermissionSet {
|
|
284
|
-
rules: PermissionRule[];
|
|
285
|
-
/** Human-readable source identifier for debugging (e.g. "default", "agent:cli-buddy", "user"). */
|
|
286
|
-
source: string;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Result of merging multiple `PermissionSet` layers.
|
|
290
|
-
* Each array contains flattened, deduplicated tool patterns for that action.
|
|
291
|
-
*/
|
|
292
|
-
interface MergedPermissions {
|
|
293
|
-
allow: string[];
|
|
294
|
-
deny: string[];
|
|
295
|
-
ask: string[];
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Hook system types for memeloop.
|
|
300
|
-
* Hooks are lifecycle callbacks that execute before/after key events in the agent loop.
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
/** Context passed to all hook handlers. */
|
|
304
|
-
type HookContext = AgentFrameworkContext;
|
|
305
|
-
/** Result returned by a hook handler. */
|
|
306
|
-
interface HookResult {
|
|
307
|
-
/** Whether to allow the action to proceed (false = block/deny) */
|
|
308
|
-
allowed: boolean;
|
|
309
|
-
/** Optional message explaining why the action was blocked */
|
|
310
|
-
reason?: string;
|
|
311
|
-
/** Optional data modified by the hook (e.g., transformed tool args) */
|
|
312
|
-
modified?: Record<string, unknown>;
|
|
313
|
-
/** Optional tool permission action. Interpreted by PreToolUse callers. */
|
|
314
|
-
permissionAction?: PermissionAction;
|
|
315
|
-
}
|
|
316
|
-
/** Signature of a hook handler function. */
|
|
317
|
-
type HookHandler = (context: HookContext, data: Record<string, unknown>) => Promise<HookResult>;
|
|
318
|
-
/** Enum of supported hook event types. */
|
|
319
|
-
type HookType = 'PreToolUse' | 'PostToolUse' | 'UserPromptSubmit' | 'ContextCompaction' | 'AgentStart' | 'AgentStop';
|
|
320
|
-
/** Data passed to PreToolUse hooks. */
|
|
321
|
-
interface PreToolUseData extends Record<string, unknown> {
|
|
322
|
-
toolId: string;
|
|
323
|
-
parameters: Record<string, unknown>;
|
|
324
|
-
conversationId: string;
|
|
325
|
-
}
|
|
326
|
-
/** Data passed to PostToolUse hooks. */
|
|
327
|
-
interface PostToolUseData extends Record<string, unknown> {
|
|
328
|
-
toolId: string;
|
|
329
|
-
parameters: Record<string, unknown>;
|
|
330
|
-
result: string;
|
|
331
|
-
isError: boolean;
|
|
332
|
-
conversationId: string;
|
|
333
|
-
}
|
|
334
|
-
/** Data passed to UserPromptSubmit hooks. */
|
|
335
|
-
interface UserPromptSubmitData extends Record<string, unknown> {
|
|
336
|
-
message: string;
|
|
337
|
-
conversationId: string;
|
|
338
|
-
}
|
|
339
|
-
/** Data passed to ContextCompaction hooks before built-in history compaction. */
|
|
340
|
-
interface ContextCompactionData extends Record<string, unknown> {
|
|
341
|
-
conversationId: string;
|
|
342
|
-
iteration: number;
|
|
343
|
-
history: ChatMessage[];
|
|
344
|
-
autoCompact?: AgentFrameworkContext['agentToolLoop'] extends infer Options ? Options extends {
|
|
345
|
-
autoCompact?: infer AutoCompact;
|
|
346
|
-
} ? AutoCompact : never : never;
|
|
347
|
-
contextCompaction?: AgentFrameworkContext['agentToolLoop'] extends infer Options ? Options extends {
|
|
348
|
-
contextCompaction?: infer ContextCompaction;
|
|
349
|
-
} ? ContextCompaction : never : never;
|
|
350
|
-
}
|
|
351
|
-
/** Data passed to AgentStart hooks. */
|
|
352
|
-
interface AgentStartData extends Record<string, unknown> {
|
|
353
|
-
conversationId: string;
|
|
354
|
-
definitionId?: string;
|
|
355
|
-
}
|
|
356
|
-
/** Data passed to AgentStop hooks. */
|
|
357
|
-
interface AgentStopData extends Record<string, unknown> {
|
|
358
|
-
conversationId: string;
|
|
359
|
-
reason: 'completed' | 'cancelled' | 'max-iterations' | 'error';
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
type LoadAgentToolLoopScriptOptions$1 = AgentLoopScriptPolicy;
|
|
363
|
-
type AgentToolLoopScriptReference$1 = AgentLoopScriptReference;
|
|
364
|
-
interface AgentToolLoopContext extends AgentFrameworkContext {
|
|
365
|
-
profile?: LoopProfile;
|
|
366
|
-
runtime?: Partial<AgentLoopRuntime>;
|
|
367
|
-
script?: AgentToolLoopScript;
|
|
368
|
-
loadScript?: (script: AgentToolLoopScriptReference$1, context: AgentToolLoopContext) => AgentToolLoopScript | Promise<AgentToolLoopScript>;
|
|
369
|
-
scriptPolicy?: LoadAgentToolLoopScriptOptions$1;
|
|
370
|
-
}
|
|
371
|
-
interface AgentToolLoopState {
|
|
372
|
-
iteration: number;
|
|
373
|
-
maxIterations: number;
|
|
374
|
-
recentToolCalls: string[];
|
|
375
|
-
agentStarted: boolean;
|
|
376
|
-
agentStopped: boolean;
|
|
377
|
-
stopReason?: AgentStopData['reason'];
|
|
378
|
-
}
|
|
379
|
-
interface AgentToolLoopTurnStartResult {
|
|
380
|
-
action: 'continue' | 'stop';
|
|
381
|
-
step?: AgentLoopStep;
|
|
382
|
-
}
|
|
383
|
-
interface AgentToolLoopIterationResult {
|
|
384
|
-
action: 'continue' | 'stop';
|
|
385
|
-
reason?: AgentStopData['reason'];
|
|
386
|
-
}
|
|
387
|
-
type AgentToolLoopIterationGenerator = AsyncGenerator<AgentLoopStep, AgentToolLoopIterationResult, void>;
|
|
388
|
-
interface AgentToolLoopScriptContext {
|
|
389
|
-
/** The host turn input. `input.message` is the user prompt for this turn. */
|
|
390
|
-
input: AgentLoopInput;
|
|
391
|
-
/** Full host context for advanced integrations. Prefer the primitive helpers below. */
|
|
392
|
-
context: AgentToolLoopContext;
|
|
393
|
-
/** Active profile selected by the registry/runtime. */
|
|
394
|
-
profile?: LoopProfile;
|
|
395
|
-
/** Create mutable loop state for one turn. Scripts can store it in checkpoints if they implement resume. */
|
|
396
|
-
createState: () => AgentToolLoopState;
|
|
397
|
-
/** Persist the user turn and run pre-agent hooks. Returns a blocking step when a hook stops the turn. */
|
|
398
|
-
startTurn: (state: AgentToolLoopState) => Promise<AgentToolLoopTurnStartResult>;
|
|
399
|
-
/** Run exactly one LLM/tool iteration. The script owns the surrounding loop policy. */
|
|
400
|
-
runIteration: (state: AgentToolLoopState) => AgentToolLoopIterationGenerator;
|
|
401
|
-
/** Run AgentStop hooks once. Pass a reason when stopping because of an error outside `runIteration`. */
|
|
402
|
-
stopTurn: (state: AgentToolLoopState, reason?: AgentStopData['reason']) => Promise<void>;
|
|
403
|
-
/** Emit a raw loop step upstream. */
|
|
404
|
-
emit: (step: AgentLoopStep) => void;
|
|
405
|
-
/** Emit a user-visible message or step. */
|
|
406
|
-
finish: (message: string | AgentLoopStep) => void;
|
|
407
|
-
/** True when host cancellation has been requested for this conversation. */
|
|
408
|
-
isCancelled: () => boolean;
|
|
409
|
-
/** Write an observability event through the runtime and host logger. */
|
|
410
|
-
log: (event: string, data?: Record<string, unknown>) => void;
|
|
411
|
-
}
|
|
412
|
-
type AgentToolLoopScriptResult = AgentLoopGenerator | AgentLoopStep | AgentLoopStep[] | string | undefined;
|
|
413
|
-
type AgentToolLoopScript = (scriptContext: AgentToolLoopScriptContext) => AgentToolLoopScriptResult | Promise<AgentToolLoopScriptResult>;
|
|
414
|
-
|
|
415
|
-
declare function createAgentToolLoopRunner(context: AgentFrameworkContext): (input: AgentLoopInput) => AgentLoopGenerator;
|
|
416
|
-
declare function createAgentToolLoopDefinition(name?: string): AgentLoopDefinition;
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* AgentToolLoop runner — convenience API for driving a full loop turn.
|
|
420
|
-
*/
|
|
421
|
-
|
|
422
|
-
interface RunAgentToolLoopTurnCallbacks {
|
|
423
|
-
onStep?: (step: AgentLoopStep) => void | Promise<void>;
|
|
424
|
-
onProgress?: (status: string, data: Record<string, unknown>, step: AgentLoopStep) => void | Promise<void>;
|
|
425
|
-
agentToolLoop?: (input: AgentLoopInput) => AgentLoopGenerator;
|
|
426
|
-
}
|
|
427
|
-
interface RunAgentToolLoopTurnResult {
|
|
428
|
-
state: AgentInstanceState;
|
|
429
|
-
stepCount: number;
|
|
430
|
-
}
|
|
431
|
-
declare function resolveAgentToolLoopTerminalState(step: AgentLoopStep, current: AgentInstanceState): AgentInstanceState;
|
|
432
|
-
declare function runAgentToolLoopTurn(context: AgentFrameworkContext, input: AgentLoopInput, callbacks?: RunAgentToolLoopTurnCallbacks): Promise<RunAgentToolLoopTurnResult>;
|
|
433
|
-
|
|
434
|
-
type LoadAgentToolLoopScriptOptions = AgentLoopScriptPolicy;
|
|
435
|
-
type AgentToolLoopScriptReference = AgentLoopScriptReference;
|
|
436
|
-
declare function loadAgentToolLoopScript(scriptReference: AgentToolLoopScriptReference, options?: LoadAgentToolLoopScriptOptions): Promise<AgentToolLoopScript>;
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Built-in loop registrations — installed at startup so getLoopRegistry().createRunner('agent-tool-loop') works.
|
|
440
|
-
*
|
|
441
|
-
* This module allows hosts to skip manual registerLoop() for the built-in loop types.
|
|
442
|
-
* Hosts can still override by calling registerLoop() with the same id after.
|
|
443
|
-
*/
|
|
444
|
-
declare const AGENT_TOOL_LOOP_ID = "agent-tool-loop";
|
|
445
|
-
declare const AGENT_AGENT_LOOP_ID: string;
|
|
446
|
-
/**
|
|
447
|
-
* Register the default built-in loops (agent-tool-loop and agent-agent-loop) with the loop registry.
|
|
448
|
-
* Safe to call multiple times — skips already-registered loops.
|
|
449
|
-
*/
|
|
450
|
-
declare function registerBuiltinLoops(): void;
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Builtin tool plugins — registers core tools as LoopPlugin entries.
|
|
454
|
-
*
|
|
455
|
-
* Each tool is a separate LoopPlugin that can be overridden by user/host plugins
|
|
456
|
-
* with the same id. The plugin.install callback calls the tool registry to
|
|
457
|
-
* register the tool implementation.
|
|
458
|
-
*
|
|
459
|
-
* These are registered in the loop registry at startup and loaded by
|
|
460
|
-
* `registerBuiltinTools` via plugin discovery.
|
|
461
|
-
*/
|
|
462
|
-
|
|
463
|
-
declare const PLUGIN_MCP_CLIENT = "builtin:mcp-client";
|
|
464
|
-
declare const PLUGIN_MCP_FORWARD = "builtin:mcp-forward";
|
|
465
|
-
declare const PLUGIN_SPAWN_AGENT = "builtin:spawn-agent";
|
|
466
|
-
declare const PLUGIN_REMOTE_AGENT = "builtin:remote-agent";
|
|
467
|
-
declare const PLUGIN_ASK_QUESTION = "builtin:ask-question";
|
|
468
|
-
declare const PLUGIN_TODO_WRITE = "builtin:todo-write";
|
|
469
|
-
declare const PLUGIN_ASK_USER_QUESTION = "builtin:ask-user-question";
|
|
470
|
-
declare const PLUGIN_TASK = "builtin:task";
|
|
471
|
-
declare const BUILTIN_TOOL_PLUGIN_IDS: readonly ["builtin:mcp-client", "builtin:mcp-forward", "builtin:spawn-agent", "builtin:remote-agent", "builtin:ask-question", "builtin:todo-write", "builtin:ask-user-question", "builtin:task"];
|
|
472
|
-
declare function getBuiltinToolPlugins(): LoopPlugin[];
|
|
473
|
-
/** Register all builtin tool plugins with the loop registry. */
|
|
474
|
-
declare function registerBuiltinToolPlugins(): void;
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* Agent loop registry.
|
|
478
|
-
*
|
|
479
|
-
* Discovers, registers, and resolves loop types, loop profiles, and loop plugins.
|
|
480
|
-
* Core does NOT hard-import any loop implementation; all are registered by host or plugin.
|
|
481
|
-
*/
|
|
482
|
-
|
|
483
|
-
type LoopPluginSelection = string | LoopProfilePluginEntry;
|
|
484
|
-
declare class LoopRegistryImpl {
|
|
485
|
-
private readonly loops;
|
|
486
|
-
private readonly profiles;
|
|
487
|
-
private readonly plugins;
|
|
488
|
-
registerLoop(definition: AgentLoopDefinition): void;
|
|
489
|
-
getLoop(id: string): AgentLoopDefinition | undefined;
|
|
490
|
-
listLoops(): AgentLoopDefinition[];
|
|
491
|
-
registerProfile(profile: LoopProfile): void;
|
|
492
|
-
getProfile(id: string): LoopProfile | undefined;
|
|
493
|
-
listProfiles(): LoopProfile[];
|
|
494
|
-
registerPlugin(plugin: LoopPlugin): void;
|
|
495
|
-
getPlugin(id: string): LoopPlugin | undefined;
|
|
496
|
-
listPlugins(): LoopPlugin[];
|
|
497
|
-
installPluginsForLoop(loopId: string, target: {
|
|
498
|
-
[key: string]: unknown;
|
|
499
|
-
}, selected?: LoopPluginSelection[]): void;
|
|
500
|
-
installPluginsForProfile(profile: LoopProfile, target: {
|
|
501
|
-
[key: string]: unknown;
|
|
502
|
-
}): void;
|
|
503
|
-
createRunnerForProfile(profile: LoopProfile, context?: {
|
|
504
|
-
[key: string]: unknown;
|
|
505
|
-
}): ((input: AgentLoopInput) => AgentLoopGenerator) | null;
|
|
506
|
-
createRunner(loopId: string, context?: {
|
|
507
|
-
[key: string]: unknown;
|
|
508
|
-
}): ((input: AgentLoopInput) => AgentLoopGenerator) | null;
|
|
509
|
-
reset(): void;
|
|
510
|
-
}
|
|
511
|
-
declare function getLoopRegistry(): LoopRegistryImpl;
|
|
512
|
-
declare function resetLoopRegistry(): void;
|
|
513
|
-
|
|
514
|
-
interface TokenTrackerConfig {
|
|
515
|
-
/** Maximum context window in tokens (default: 200000) */
|
|
516
|
-
contextWindow?: number;
|
|
517
|
-
/** Trigger compaction when usage exceeds this fraction (default: 0.90) */
|
|
518
|
-
compactionThreshold?: number;
|
|
519
|
-
/** Buffer tokens reserved for output (default: 16000) */
|
|
520
|
-
outputBuffer?: number;
|
|
521
|
-
}
|
|
522
|
-
interface TokenUsage {
|
|
523
|
-
promptTokens: number;
|
|
524
|
-
completionTokens: number;
|
|
525
|
-
totalTokens: number;
|
|
526
|
-
contextWindow: number;
|
|
527
|
-
usagePercent: number;
|
|
528
|
-
shouldCompact: boolean;
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* Tracks token usage and decides when to trigger auto-compaction.
|
|
532
|
-
*/
|
|
533
|
-
declare class TokenTracker {
|
|
534
|
-
private promptTokens;
|
|
535
|
-
private completionTokens;
|
|
536
|
-
private readonly contextWindow;
|
|
537
|
-
private readonly compactionThreshold;
|
|
538
|
-
private readonly outputBuffer;
|
|
539
|
-
private compacting;
|
|
540
|
-
private consecutiveCompactionFailures;
|
|
541
|
-
private maxConsecutiveFailures;
|
|
542
|
-
constructor(config?: TokenTrackerConfig);
|
|
543
|
-
/** Record token usage from an LLM response */
|
|
544
|
-
recordUsage(promptTokens: number, completionTokens: number): void;
|
|
545
|
-
/** Manually set the prompt token count (e.g., from estimation) */
|
|
546
|
-
setPromptTokens(tokens: number): void;
|
|
547
|
-
/** Get current usage */
|
|
548
|
-
getUsage(): TokenUsage;
|
|
549
|
-
/** Check if auto-compaction should be triggered */
|
|
550
|
-
shouldTriggerCompaction(): boolean;
|
|
551
|
-
/** Mark that compaction is starting */
|
|
552
|
-
markCompactionStart(): void;
|
|
553
|
-
/** Mark that compaction succeeded — reset token counts */
|
|
554
|
-
markCompactionSuccess(estimatedPostTokens: number): void;
|
|
555
|
-
/** Mark that compaction failed */
|
|
556
|
-
markCompactionFailure(): void;
|
|
557
|
-
/** Reset all counters */
|
|
558
|
-
reset(): void;
|
|
559
|
-
/** Get a human-readable summary */
|
|
560
|
-
formatUsage(): string;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
interface CreateAgentOptions {
|
|
564
|
-
definitionId: string;
|
|
565
|
-
initialMessage?: string;
|
|
566
|
-
}
|
|
567
|
-
interface SendMessageOptions {
|
|
568
|
-
conversationId: string;
|
|
569
|
-
message: string;
|
|
570
|
-
definitionId?: string;
|
|
571
|
-
userMessage?: AgentLoopInput['userMessage'];
|
|
572
|
-
resumeSession?: ChatMessage[];
|
|
573
|
-
}
|
|
574
|
-
interface MemeLoopRuntime {
|
|
575
|
-
createAgent(options: CreateAgentOptions): Promise<{
|
|
576
|
-
conversationId: string;
|
|
577
|
-
}>;
|
|
578
|
-
sendMessage(options: SendMessageOptions): Promise<void>;
|
|
579
|
-
cancelAgent(conversationId: string): Promise<void>;
|
|
580
|
-
subscribeToUpdates(conversationId: string, listener: (update: unknown) => void): () => void;
|
|
581
|
-
}
|
|
582
|
-
interface CreateAgentLoopRunnerOptions {
|
|
583
|
-
definitionId: string;
|
|
584
|
-
conversationId?: string;
|
|
585
|
-
}
|
|
586
|
-
declare function createAgentLoopRunner(context: AgentFrameworkContext, options: CreateAgentLoopRunnerOptions): Promise<((input: AgentLoopInput) => AgentLoopGenerator) | null>;
|
|
587
|
-
declare function createMemeLoopRuntime(context: AgentFrameworkContext): MemeLoopRuntime;
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Built-in Loop Profiles.
|
|
591
|
-
*
|
|
592
|
-
* Each profile defines which agent loop to run, which .mjs script to load,
|
|
593
|
-
* which prompts, plugins, and hook plugins to enable.
|
|
594
|
-
*
|
|
595
|
-
* Replaces the old `src/prompt/loadBuiltins.ts`.
|
|
596
|
-
*/
|
|
597
|
-
|
|
598
|
-
/** Get all built-in Loop Profiles. */
|
|
599
|
-
declare function getBuiltinLoopProfiles(): LoopProfile[];
|
|
600
|
-
/** Get a built-in Loop Profile by id. */
|
|
601
|
-
declare function getBuiltinLoopProfile(id: string): LoopProfile | undefined;
|
|
602
|
-
/** Register bundled profiles with the global loop registry. */
|
|
603
|
-
declare function registerBuiltinLoopProfiles(): void;
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* Extended agent definition used by the agent profile registry.
|
|
607
|
-
* Wraps the protocol-level AgentDefinition with additional runtime metadata.
|
|
608
|
-
*/
|
|
609
|
-
interface AgentProfile {
|
|
610
|
-
/** Unique ID for this agent (matches protocol id convention like "memeloop:build") */
|
|
611
|
-
id: string;
|
|
612
|
-
/** Display name */
|
|
613
|
-
name: string;
|
|
614
|
-
/** Agent type / role */
|
|
615
|
-
type: AgentProfileType;
|
|
616
|
-
/** System prompt / instructions for the agent */
|
|
617
|
-
prompt: string;
|
|
618
|
-
/** Tool permission rules (mutually exclusive with permissive defaults) */
|
|
619
|
-
permissions: ToolPermissionRules;
|
|
620
|
-
/** Optional model override (provider/model string) */
|
|
621
|
-
model?: string;
|
|
622
|
-
/** Underlying protocol-compatible definition for framework integration */
|
|
623
|
-
protocolDef: AgentDefinition;
|
|
624
|
-
}
|
|
625
|
-
type AgentProfileType = 'build' | 'plan' | 'explore' | 'oracle' | 'librarian';
|
|
626
|
-
interface ToolPermissionRules {
|
|
627
|
-
/** Default action for tools not matching any rule */
|
|
628
|
-
default: 'allow' | 'ask' | 'deny';
|
|
629
|
-
/** Per-tool or wildcard rules */
|
|
630
|
-
rules: Array<{
|
|
631
|
-
pattern: string;
|
|
632
|
-
action: 'allow' | 'ask' | 'deny';
|
|
633
|
-
}>;
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* Build agent: full access, default model.
|
|
637
|
-
* Primary agent for executing tasks, writing code, running commands.
|
|
638
|
-
*/
|
|
639
|
-
declare const buildAgent: AgentProfile;
|
|
640
|
-
/**
|
|
641
|
-
* Plan agent: read-only, denies file edits and terminal execution.
|
|
642
|
-
* Used for high-level planning and task decomposition.
|
|
643
|
-
*/
|
|
644
|
-
declare const planAgent: AgentProfile;
|
|
645
|
-
/**
|
|
646
|
-
* Explore agent: read + search tools only.
|
|
647
|
-
* Fast search and codebase exploration without modification.
|
|
648
|
-
*/
|
|
649
|
-
declare const exploreAgent: AgentProfile;
|
|
650
|
-
/**
|
|
651
|
-
* Oracle agent: read-only, for architecture consultation and code review.
|
|
652
|
-
*/
|
|
653
|
-
declare const oracleAgent: AgentProfile;
|
|
654
|
-
/**
|
|
655
|
-
* Librarian agent: read + web search tools only.
|
|
656
|
-
* External documentation lookup and context gathering.
|
|
657
|
-
*/
|
|
658
|
-
declare const librarianAgent: AgentProfile;
|
|
659
|
-
/** Built-in agent profiles used by the task delegation tool. */
|
|
660
|
-
declare const BUILTIN_AGENT_PROFILES: AgentProfile[];
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* Registry for agent profiles used by task delegation.
|
|
664
|
-
* Pre-seeded with built-in profiles (build, plan, explore, oracle, librarian).
|
|
665
|
-
*/
|
|
666
|
-
declare class AgentProfileRegistry {
|
|
667
|
-
private readonly profiles;
|
|
668
|
-
constructor();
|
|
669
|
-
/** Seed the registry with built-in agent profiles. */
|
|
670
|
-
private seedDefaults;
|
|
671
|
-
/**
|
|
672
|
-
* Register a new agent profile or override an existing one.
|
|
673
|
-
* Throws if the profile is invalid.
|
|
674
|
-
*/
|
|
675
|
-
registerAgentProfile(profile: AgentProfile): void;
|
|
676
|
-
/**
|
|
677
|
-
* Get an agent profile by ID.
|
|
678
|
-
* Returns undefined if not found.
|
|
679
|
-
*/
|
|
680
|
-
getAgentProfile(id: string): AgentProfile | undefined;
|
|
681
|
-
/**
|
|
682
|
-
* List all registered agent profiles.
|
|
683
|
-
*/
|
|
684
|
-
listAgentProfiles(): AgentProfile[];
|
|
685
|
-
/**
|
|
686
|
-
* List agent profiles filtered by type.
|
|
687
|
-
*/
|
|
688
|
-
listAgentProfilesByType(type: AgentProfileType): AgentProfile[];
|
|
689
|
-
/**
|
|
690
|
-
* Remove an agent profile by ID.
|
|
691
|
-
*/
|
|
692
|
-
unregisterAgentProfile(id: string): boolean;
|
|
693
|
-
/**
|
|
694
|
-
* Reset the registry to only built-in defaults.
|
|
695
|
-
*/
|
|
696
|
-
reset(): void;
|
|
697
|
-
}
|
|
698
|
-
declare function getAgentProfileRegistry(): AgentProfileRegistry;
|
|
699
|
-
declare function resetAgentProfileRegistry(): void;
|
|
700
|
-
|
|
701
|
-
/**
|
|
702
|
-
* Task category system for routing tasks to appropriate agent configurations.
|
|
703
|
-
* Each category maps to a model, temperature, and description for delegation decisions.
|
|
704
|
-
*/
|
|
705
|
-
type TaskCategory = 'visual-engineering' | 'ultrabrain' | 'artistry' | 'quick' | 'unspecified-low' | 'unspecified-high' | 'writing';
|
|
706
|
-
interface CategoryConfig {
|
|
707
|
-
/** Model identifier (e.g., "default", "gpt-4o", "claude-opus") */
|
|
708
|
-
model: string;
|
|
709
|
-
/** LLM temperature (0.0 = deterministic, 1.0 = creative) */
|
|
710
|
-
temperature: number;
|
|
711
|
-
/** Human-readable description of the category's purpose */
|
|
712
|
-
description: string;
|
|
713
|
-
}
|
|
714
|
-
/**
|
|
715
|
-
* Get the configuration for a task category.
|
|
716
|
-
* @throws {Error} if the category is unknown
|
|
717
|
-
*/
|
|
718
|
-
declare function getCategoryConfig(category: TaskCategory): CategoryConfig;
|
|
719
|
-
/**
|
|
720
|
-
* Type guard: check if a string is a valid TaskCategory.
|
|
721
|
-
*/
|
|
722
|
-
declare function isTaskCategory(value: string): value is TaskCategory;
|
|
723
|
-
/** All registered category identifiers (read-only). */
|
|
724
|
-
declare const ALL_CATEGORIES: TaskCategory[];
|
|
725
|
-
/**
|
|
726
|
-
* Resolve a category string (or fallback to "unspecified-low").
|
|
727
|
-
* Never throws; always returns a valid config.
|
|
728
|
-
*/
|
|
729
|
-
declare function resolveCategory(category: string): CategoryConfig;
|
|
730
|
-
|
|
731
|
-
/**
|
|
732
|
-
* Provider-agnostic LLM provider — wraps any Vercel AI SDK LanguageModelV1.
|
|
733
|
-
*
|
|
734
|
-
* The core does NOT depend on @ai-sdk/openai or any specific provider.
|
|
735
|
-
* Hosts inject their own `createModel` factory:
|
|
736
|
-
*
|
|
737
|
-
* import { createOpenAI } from '@ai-sdk/openai';
|
|
738
|
-
* const openai = createOpenAI({ baseURL: '...', apiKey: '...' });
|
|
739
|
-
* const provider = createFetchLLMProvider({
|
|
740
|
-
* name: 'openai',
|
|
741
|
-
* createModel: (id) => openai(id ?? 'gpt-4o-mini'),
|
|
742
|
-
* });
|
|
743
|
-
*
|
|
744
|
-
* Or for Anthropic:
|
|
745
|
-
* import { createAnthropic } from '@ai-sdk/anthropic';
|
|
746
|
-
* const anthropic = createAnthropic({ apiKey: '...' });
|
|
747
|
-
* const provider = createFetchLLMProvider({
|
|
748
|
-
* name: 'claude',
|
|
749
|
-
* createModel: (id) => anthropic(id ?? 'claude-3-5-sonnet-20241022'),
|
|
750
|
-
* });
|
|
751
|
-
*
|
|
752
|
-
* Works with every @ai-sdk/* provider: openai, anthropic, google, deepseek,
|
|
753
|
-
* cohere, mistral, azure, bedrock, groq, ollama, openrouter, together, etc.
|
|
754
|
-
*/
|
|
755
|
-
|
|
756
|
-
interface FetchLLMProviderConfig {
|
|
757
|
-
/** Display name. */
|
|
758
|
-
name: string;
|
|
759
|
-
/**
|
|
760
|
-
* Factory: given an optional model id, return a LanguageModelV1 from any @ai-sdk/* provider.
|
|
761
|
-
* The factory is responsible for picking a default model when `modelId` is omitted.
|
|
762
|
-
*/
|
|
763
|
-
createModel: (modelId?: string) => LanguageModelV1;
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* Create an `ILLMProvider` that delegates to the Vercel AI SDK.
|
|
767
|
-
*
|
|
768
|
-
* Provider-agnostic — hosts supply their own `createModel` factory.
|
|
769
|
-
* Supports every @ai-sdk/* provider (OpenAI, Anthropic, Google, DeepSeek,
|
|
770
|
-
* Groq, Ollama, OpenRouter, Together, Bedrock, Azure, Mistral, Cohere…).
|
|
771
|
-
*
|
|
772
|
-
* @example
|
|
773
|
-
* ```ts
|
|
774
|
-
* import { createOpenAI } from '@ai-sdk/openai';
|
|
775
|
-
* const openai = createOpenAI({ baseURL: 'https://api.openai.com/v1', apiKey });
|
|
776
|
-
* const provider = createFetchLLMProvider({
|
|
777
|
-
* name: 'openai',
|
|
778
|
-
* createModel: (modelId) => openai(modelId ?? 'gpt-4o-mini'),
|
|
779
|
-
* });
|
|
780
|
-
* ```
|
|
781
|
-
*/
|
|
782
|
-
declare function createFetchLLMProvider(config: FetchLLMProviderConfig): ILLMProvider;
|
|
783
|
-
|
|
784
|
-
interface ProviderConfig {
|
|
785
|
-
name: string;
|
|
786
|
-
baseUrl?: string;
|
|
787
|
-
apiKey?: string;
|
|
788
|
-
}
|
|
789
|
-
interface RegisteredProvider {
|
|
790
|
-
provider: ILLMProvider;
|
|
791
|
-
config: ProviderConfig;
|
|
792
|
-
}
|
|
793
|
-
declare class ProviderRegistry {
|
|
794
|
-
private providers;
|
|
795
|
-
register(provider: ILLMProvider, config?: Omit<ProviderConfig, 'name'>): void;
|
|
796
|
-
unregister(name: string): void;
|
|
797
|
-
get(name: string): ILLMProvider | undefined;
|
|
798
|
-
getConfig(name: string): ProviderConfig | undefined;
|
|
799
|
-
upsertConfig(config: ProviderConfig): void;
|
|
800
|
-
list(): string[];
|
|
801
|
-
listConfigs(): ProviderConfig[];
|
|
802
|
-
resolve(modelId: string): {
|
|
803
|
-
provider: ILLMProvider;
|
|
804
|
-
providerName: string;
|
|
805
|
-
modelName?: string;
|
|
806
|
-
};
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
/**
|
|
810
|
-
* Hook registry for managing lifecycle hook handlers.
|
|
811
|
-
* Hooks execute in registration order (first registered, first executed).
|
|
812
|
-
*
|
|
813
|
-
* Converted from module-level singletons to an instance class for test isolation
|
|
814
|
-
* and multi-runtime support. Backward-compatible function exports delegate to a
|
|
815
|
-
* default global instance.
|
|
816
|
-
*/
|
|
817
|
-
|
|
818
|
-
/**
|
|
819
|
-
* Instance-level hook registry. Each instance maintains its own handler state.
|
|
820
|
-
*/
|
|
821
|
-
declare class HookRegistry {
|
|
822
|
-
private readonly hookRegistry;
|
|
823
|
-
private readonly hookOrder;
|
|
824
|
-
/**
|
|
825
|
-
* Register a hook handler for a specific lifecycle event.
|
|
826
|
-
*/
|
|
827
|
-
registerHook(type: HookType, handler: HookHandler, name?: string): void;
|
|
828
|
-
/**
|
|
829
|
-
* Unregister a specific hook handler by name.
|
|
830
|
-
*/
|
|
831
|
-
unregisterHook(type: HookType, name: string): boolean;
|
|
832
|
-
/**
|
|
833
|
-
* Execute all registered hooks for a given type in registration order.
|
|
834
|
-
*/
|
|
835
|
-
executeHooks(type: HookType, context: HookContext, data: Record<string, unknown>): Promise<HookResult>;
|
|
836
|
-
/**
|
|
837
|
-
* Check if any hooks are registered for a given type.
|
|
838
|
-
*/
|
|
839
|
-
hasHooks(type: HookType): boolean;
|
|
840
|
-
/**
|
|
841
|
-
* Remove all registered hooks of all types.
|
|
842
|
-
*/
|
|
843
|
-
clearHooks(): void;
|
|
844
|
-
/**
|
|
845
|
-
* List all hook types that have at least one registered handler.
|
|
846
|
-
*/
|
|
847
|
-
listRegisteredHookTypes(): HookType[];
|
|
848
|
-
/**
|
|
849
|
-
* Get the count of registered handlers for a hook type.
|
|
850
|
-
*/
|
|
851
|
-
getHookCount(type: HookType): number;
|
|
852
|
-
}
|
|
853
|
-
declare function getDefaultHookRegistry(): HookRegistry;
|
|
854
|
-
declare function registerHook(type: HookType, handler: HookHandler, name?: string): void;
|
|
855
|
-
declare function unregisterHook(type: HookType, name: string): boolean;
|
|
856
|
-
declare function executeHooks(type: HookType, context: HookContext, data: Record<string, unknown>): Promise<HookResult>;
|
|
857
|
-
declare function hasHooks(type: HookType): boolean;
|
|
858
|
-
declare function clearHooks(): void;
|
|
859
|
-
declare function listRegisteredHookTypes(): HookType[];
|
|
860
|
-
/**
|
|
861
|
-
* Get the count of registered handlers for a hook type.
|
|
862
|
-
*/
|
|
863
|
-
declare function getHookCount(type: HookType): number;
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
* Test whether a tool name matches a wildcard pattern.
|
|
867
|
-
*
|
|
868
|
-
* Supported patterns:
|
|
869
|
-
* - `*` → matches everything
|
|
870
|
-
* - `file.*` → matches any tool starting with `file.`
|
|
871
|
-
* - `shell(*)` → matches tools like `shell(rm)`, `shell(ls)` (literal parens)
|
|
872
|
-
* - exact name → matches only that exact tool name
|
|
873
|
-
*
|
|
874
|
-
* Patterns are converted to anchored regexes internally.
|
|
875
|
-
*/
|
|
876
|
-
declare function matchPattern(toolName: string, pattern: string): boolean;
|
|
877
|
-
/**
|
|
878
|
-
* Merge multiple permission sets from lowest to highest priority.
|
|
879
|
-
*
|
|
880
|
-
* Sets are processed in order; later rules override earlier ones for the same tool pattern.
|
|
881
|
-
* Within a single set, rules are processed in order (last wins).
|
|
882
|
-
*
|
|
883
|
-
* @param sets - Ordered from lowest to highest priority (e.g. default → agent → user → session)
|
|
884
|
-
* @returns Flattened `MergedPermissions` with all unique patterns per action.
|
|
885
|
-
*/
|
|
886
|
-
declare function mergePermissionSets(sets: PermissionSet[]): MergedPermissions;
|
|
887
|
-
/**
|
|
888
|
-
* Check what action applies to a given tool name under merged permissions.
|
|
889
|
-
*
|
|
890
|
-
* Precedence: exact patterns always beat wildcards.
|
|
891
|
-
* Within same specificity: deny > ask > allow.
|
|
892
|
-
*/
|
|
893
|
-
declare function checkPermission(toolName: string, merged: MergedPermissions): PermissionAction;
|
|
894
|
-
|
|
895
|
-
interface PermissionSqlStatement {
|
|
896
|
-
get(...arguments_: unknown[]): unknown;
|
|
897
|
-
run(...arguments_: unknown[]): unknown;
|
|
898
|
-
}
|
|
899
|
-
interface PermissionSqlDatabase {
|
|
900
|
-
prepare(sql: string): PermissionSqlStatement;
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* Load user-level permission set from SQLite.
|
|
904
|
-
*
|
|
905
|
-
* The `permissions` table stores JSON blobs keyed by `source`.
|
|
906
|
-
* Returns an empty set if no persisted rules exist.
|
|
907
|
-
*/
|
|
908
|
-
declare function loadUserPermissions(database: PermissionSqlDatabase): PermissionSet;
|
|
909
|
-
/**
|
|
910
|
-
* Persist user-level permission set to SQLite.
|
|
911
|
-
*
|
|
912
|
-
* Uses INSERT OR REPLACE so first-time saves work without explicit table detection.
|
|
913
|
-
*/
|
|
914
|
-
declare function saveUserPermissions(database: PermissionSqlDatabase, set: PermissionSet): void;
|
|
915
|
-
/** SQL statement to create the permissions table during migration. */
|
|
916
|
-
declare const PERMISSIONS_TABLE_DDL = "\n CREATE TABLE IF NOT EXISTS permissions (\n source TEXT PRIMARY KEY,\n rulesJson TEXT NOT NULL,\n updatedAt INTEGER NOT NULL\n );\n";
|
|
917
|
-
|
|
918
|
-
/**
|
|
919
|
-
* Plugin marketplace architecture types.
|
|
920
|
-
* Plugins can provide tools and hooks to extend memeloop.
|
|
921
|
-
*/
|
|
922
|
-
|
|
923
|
-
/**
|
|
924
|
-
* Plugin manifest schema.
|
|
925
|
-
* Host adapters may read this from files or construct it programmatically.
|
|
926
|
-
*/
|
|
927
|
-
interface PluginManifest {
|
|
928
|
-
/** Unique plugin identifier (e.g. "plugin-hello", "@scope/my-plugin") */
|
|
929
|
-
name: string;
|
|
930
|
-
/** Semantic version */
|
|
931
|
-
version: string;
|
|
932
|
-
/** Human-readable description */
|
|
933
|
-
description: string;
|
|
934
|
-
/** Declared exports: what the plugin provides */
|
|
935
|
-
exports?: PluginExports;
|
|
936
|
-
/** Plugin author */
|
|
937
|
-
author?: string;
|
|
938
|
-
/** Minimum memeloop version requirement (semver range) */
|
|
939
|
-
minMemeloopVersion?: string;
|
|
940
|
-
}
|
|
941
|
-
/** Declared capabilities a plugin may export. */
|
|
942
|
-
interface PluginExports {
|
|
943
|
-
/** Tool IDs this plugin implements */
|
|
944
|
-
tools?: string[];
|
|
945
|
-
/** Hook types this plugin listens for */
|
|
946
|
-
hooks?: HookType[];
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
* Shape of a loaded plugin module's default export.
|
|
950
|
-
* Plugins must export default an object conforming to this interface.
|
|
951
|
-
*/
|
|
952
|
-
interface PluginModule {
|
|
953
|
-
/** Plugin identity (must match manifest name) */
|
|
954
|
-
name: string;
|
|
955
|
-
/**
|
|
956
|
-
* Called when the plugin is loaded. Receives the PluginAPI for registering
|
|
957
|
-
* tools and hooks. Return a cleanup function for teardown.
|
|
958
|
-
*/
|
|
959
|
-
activate: (api: PluginAPI) => (() => void) | Promise<() => void> | undefined;
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* API surface exposed to plugins. Plugins call these methods in their
|
|
963
|
-
* `activate` function to register their capabilities.
|
|
964
|
-
*/
|
|
965
|
-
interface PluginAPI {
|
|
966
|
-
/**
|
|
967
|
-
* Register a tool implementation.
|
|
968
|
-
* @param toolId - Unique tool ID (e.g. "plugin-hello.sayHi")
|
|
969
|
-
* @param impl - Tool implementation function
|
|
970
|
-
* @param schema - Optional parameter schema (Zod type)
|
|
971
|
-
*/
|
|
972
|
-
registerTool(toolId: string, impl: (...arguments_: unknown[]) => unknown, schema?: unknown): void;
|
|
973
|
-
/**
|
|
974
|
-
* Register a lifecycle hook handler.
|
|
975
|
-
* @param type - Hook event type
|
|
976
|
-
* @param handler - Async handler function
|
|
977
|
-
* @param name - Optional handler name (enables dedup/unregistration)
|
|
978
|
-
*/
|
|
979
|
-
registerHook(type: HookType, handler: HookHandler, name?: string): void;
|
|
980
|
-
/** Log to memeloop's logger (falls back to console). */
|
|
981
|
-
logger: {
|
|
982
|
-
debug: (message: string, ...arguments_: unknown[]) => void;
|
|
983
|
-
info: (message: string, ...arguments_: unknown[]) => void;
|
|
984
|
-
warn: (message: string, ...arguments_: unknown[]) => void;
|
|
985
|
-
error: (message: string, ...arguments_: unknown[]) => void;
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
/** Metadata about a loaded plugin instance. */
|
|
989
|
-
interface LoadedPlugin {
|
|
990
|
-
/** Manifest data */
|
|
991
|
-
manifest: PluginManifest;
|
|
992
|
-
/** Optional host-provided source identifier, e.g. package name or file path. */
|
|
993
|
-
source: string;
|
|
994
|
-
/** The loaded plugin module */
|
|
995
|
-
module: PluginModule;
|
|
996
|
-
/** Cleanup function returned by activate(), if any */
|
|
997
|
-
cleanup: (() => void) | undefined;
|
|
998
|
-
/** When the plugin was loaded */
|
|
999
|
-
loadedAt: Date;
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
declare function validatePluginManifest(object: unknown): PluginManifest | null;
|
|
1003
|
-
interface LoadPluginModuleOptions {
|
|
1004
|
-
manifest: PluginManifest;
|
|
1005
|
-
module: PluginModule;
|
|
1006
|
-
api?: unknown;
|
|
1007
|
-
source?: string;
|
|
1008
|
-
}
|
|
1009
|
-
declare function loadPluginModule(options: LoadPluginModuleOptions): Promise<LoadedPlugin | null>;
|
|
1010
|
-
declare function loadPluginModules(plugins: LoadPluginModuleOptions[]): Promise<LoadedPlugin[]>;
|
|
1011
|
-
declare function unloadPlugin(name: string): boolean;
|
|
1012
|
-
declare function listPlugins(): LoadedPlugin[];
|
|
1013
|
-
declare function getLoadedPlugin(name: string): LoadedPlugin | undefined;
|
|
1014
|
-
declare function isPluginLoaded(name: string): boolean;
|
|
1015
|
-
declare function unloadAllPlugins(): void;
|
|
1016
|
-
|
|
1017
|
-
/**
|
|
1018
|
-
* Plugin registry: bridges plugin exports to memeloop's tool and hook registries.
|
|
1019
|
-
*
|
|
1020
|
-
* Provides a `createPluginAPI()` factory that plugins call during `activate()`
|
|
1021
|
-
* to register their tools and hooks with the host runtime.
|
|
1022
|
-
*
|
|
1023
|
-
* Converted from module-level singletons to an instance class for test isolation
|
|
1024
|
-
* and multi-runtime support.
|
|
1025
|
-
*/
|
|
1026
|
-
|
|
1027
|
-
/** Plugin API factory options. */
|
|
1028
|
-
interface PluginAPIOptions {
|
|
1029
|
-
toolRegistry?: {
|
|
1030
|
-
registerTool(id: string, impl: unknown): void;
|
|
1031
|
-
};
|
|
1032
|
-
logger?: PluginAPI['logger'];
|
|
1033
|
-
}
|
|
1034
|
-
/**
|
|
1035
|
-
* Track which tools/plugins belong to each plugin so we can clean up on unload.
|
|
1036
|
-
*/
|
|
1037
|
-
interface PluginRegistration {
|
|
1038
|
-
pluginName: string;
|
|
1039
|
-
tools: string[];
|
|
1040
|
-
hooks: Array<{
|
|
1041
|
-
type: HookType;
|
|
1042
|
-
name: string;
|
|
1043
|
-
}>;
|
|
1044
|
-
}
|
|
1045
|
-
declare function createPluginAPI(options?: PluginAPIOptions): PluginAPI;
|
|
1046
|
-
declare function registerPluginTools(pluginName: string, tools: Array<readonly [string, (...arguments_: unknown[]) => unknown, unknown?]>): void;
|
|
1047
|
-
declare function registerPluginHooks(pluginName: string, hooks: Array<readonly [HookType, HookHandler, string?]>): void;
|
|
1048
|
-
declare function getPluginRegistrations(pluginName: string): PluginRegistration | undefined;
|
|
1049
|
-
declare function clearPluginRegistrations(): void;
|
|
1050
|
-
|
|
1051
|
-
/**
|
|
1052
|
-
* 注册内置 prompt 插件(fullReplacement、dynamicPosition)。
|
|
1053
|
-
* @param target 若传入(如节点 `ToolRegistry` 上的 Map),只写入该表;否则写入活动注册表(全局或 ALS)。
|
|
1054
|
-
*/
|
|
1055
|
-
declare function registerBuiltinPromptPlugins(target?: Map<string, PromptConcatTool>): void;
|
|
1056
|
-
|
|
1057
|
-
/** 扁平化后的 LLM 消息(不依赖 peer `ai` 包导出,避免 d.ts 与 SDK 主版本不一致) */
|
|
1058
|
-
type PromptFlatModelMessage = {
|
|
1059
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
1060
|
-
content: unknown;
|
|
1061
|
-
};
|
|
1062
|
-
declare function findPromptById(prompts: PromptNode[], id: string): {
|
|
1063
|
-
prompt: PromptNode;
|
|
1064
|
-
parent: PromptNode[];
|
|
1065
|
-
index: number;
|
|
1066
|
-
} | undefined;
|
|
1067
|
-
declare function flattenPrompts(prompts: PromptNode[]): PromptFlatModelMessage[];
|
|
1068
|
-
interface PromptConcatPluginPreview {
|
|
1069
|
-
id: string;
|
|
1070
|
-
toolId?: string;
|
|
1071
|
-
caption?: string;
|
|
1072
|
-
}
|
|
1073
|
-
interface PromptConcatStreamState {
|
|
1074
|
-
processedPrompts: PromptNode[];
|
|
1075
|
-
flatPrompts: PromptFlatModelMessage[];
|
|
1076
|
-
step: 'flatten' | 'complete' | 'plugin' | 'finalize';
|
|
1077
|
-
isComplete: boolean;
|
|
1078
|
-
/** prompt 节点 id → JSON 路径(如 agentFrameworkConfig.prompts.0) */
|
|
1079
|
-
sourcePaths?: Record<string, string>;
|
|
1080
|
-
/** Desktop UI: plugin currently being processed. */
|
|
1081
|
-
currentPlugin?: PromptConcatPluginPreview;
|
|
1082
|
-
/** Desktop UI: progress value between 0 and 1. */
|
|
1083
|
-
progress?: number;
|
|
1084
|
-
}
|
|
1085
|
-
interface PromptConcatOptions {
|
|
1086
|
-
readAttachmentFile?: (path: string) => Promise<Uint8Array | Buffer>;
|
|
1087
|
-
}
|
|
1088
|
-
declare function promptConcatStream(agentConfig: Pick<AgentPromptDescription, 'agentFrameworkConfig'>, messages: ChatMessage[], agentFrameworkContext: AgentFrameworkContext, options?: PromptConcatOptions): AsyncGenerator<PromptConcatStreamState, PromptConcatStreamState, unknown>;
|
|
1089
|
-
|
|
1090
|
-
export { type MergedPermissions as $, AGENT_AGENT_LOOP_ID as A, type AgentToolLoopScriptContext as B, type AgentToolLoopScriptReference as C, type AgentToolLoopState as D, type AgentToolLoopTurnStartResult as E, BUILTIN_AGENT_AGENT_LOOP_QUALITY_GATE_SCRIPT_ID as F, BUILTIN_AGENT_PROFILES as G, BUILTIN_AGENT_TOOL_LOOP_DEFAULT_SCRIPT_ID as H, BUILTIN_TOOL_PLUGIN_IDS as I, type CategoryConfig as J, type CompactionOptions as K, type CompactionResult as L, type MemeLoopRuntime as M, type ContextCompactionData as N, type CreateAgentLoopRunnerOptions as O, type CreateAgentOptions as P, type FetchLLMProviderConfig as Q, type HookContext as R, type HookHandler as S, HookRegistry as T, type HookResult as U, type HookType as V, type LoadAgentAgentLoopScriptOptions as W, type LoadAgentToolLoopScriptOptions as X, type LoadPluginModuleOptions as Y, type LoadedPlugin as Z, LoopRegistryImpl as _, AGENT_TOOL_LOOP_ID as a, getLoadedPlugin as a$, PERMISSIONS_TABLE_DDL as a0, PLUGIN_ASK_QUESTION as a1, PLUGIN_ASK_USER_QUESTION as a2, PLUGIN_MCP_CLIENT as a3, PLUGIN_MCP_FORWARD as a4, PLUGIN_REMOTE_AGENT as a5, PLUGIN_SPAWN_AGENT as a6, PLUGIN_TASK as a7, PLUGIN_TODO_WRITE as a8, type PermissionAction as a9, builtinAgentToolLoopSources as aA, checkPermission as aB, clearHooks as aC, clearPluginRegistrations as aD, compactMessages as aE, createAgentAgentLoopDefinition as aF, createAgentInstanceFromDefinition as aG, createAgentLoopRunner as aH, createAgentToolLoopDefinition as aI, createAgentToolLoopRunner as aJ, createChatMessage as aK, createFetchLLMProvider as aL, createMemeLoopRuntime as aM, createPluginAPI as aN, executeHooks as aO, exploreAgent as aP, flattenPrompts as aQ, getAgentAgentLoopId as aR, getAgentProfileRegistry as aS, getBuiltinAgentAgentLoopSource as aT, getBuiltinAgentToolLoopSource as aU, getBuiltinLoopProfile as aV, getBuiltinLoopProfiles as aW, getBuiltinToolPlugins as aX, getCategoryConfig as aY, getDefaultHookRegistry as aZ, getHookCount as a_, type PermissionRule as aa, type PermissionSet as ab, type PermissionSqlDatabase as ac, type PermissionSqlStatement as ad, type PluginAPI as ae, type PluginAPIOptions as af, type PluginExports as ag, type PluginManifest as ah, type PluginModule as ai, type PostToolUseData as aj, type PreToolUseData as ak, type PromptConcatPluginPreview as al, type PromptConcatStreamState as am, type ProviderConfig as an, ProviderRegistry as ao, type RegisteredProvider as ap, type RunAgentToolLoopTurnCallbacks as aq, type RunAgentToolLoopTurnResult as ar, type SendMessageOptions as as, type TaskCategory as at, TokenTracker as au, type ToolPermissionRules as av, type UserPromptSubmitData as aw, autoCompact as ax, buildAgent as ay, builtinAgentAgentLoopSources as az, ALL_CATEGORIES as b, getLoopRegistry as b0, getPluginRegistrations as b1, hasHooks as b2, isPluginLoaded as b3, isTaskCategory as b4, librarianAgent as b5, listPlugins as b6, listRegisteredHookTypes as b7, loadAgentAgentLoopScript as b8, loadAgentToolLoopScript as b9, loadPluginModule as ba, loadPluginModules as bb, loadUserPermissions as bc, matchPattern as bd, mergePermissionSets as be, oracleAgent as bf, planAgent as bg, promptConcatStream as bh, registerBuiltinLoops as bi, registerBuiltinPromptPlugins as bj, registerBuiltinToolPlugins as bk, registerHook as bl, registerPluginHooks as bm, registerPluginTools as bn, resetAgentProfileRegistry as bo, resetLoopRegistry as bp, resolveAgentToolLoopTerminalState as bq, resolveCategory as br, runAgentToolLoopTurn as bs, saveUserPermissions as bt, shouldCompact as bu, unloadAllPlugins as bv, unloadPlugin as bw, unregisterHook as bx, validatePluginManifest as by, registerBuiltinLoopProfiles as bz, type AgentAgentBatchRunInput as c, type AgentAgentBatchRunResult as d, type AgentAgentConfigEntry as e, findPromptById as f, type AgentAgentContext as g, type AgentAgentDescriptor as h, type AgentAgentFormatResultsOptions as i, type AgentAgentLoopContext as j, type AgentAgentLoopScript as k, type AgentAgentLoopScriptArguments as l, type AgentAgentLoopScriptReference as m, type AgentAgentRunAgentFailure as n, type AgentAgentRunAgentInput as o, type AgentAgentRunAgentResult as p, type AgentAgentScriptContext as q, type AgentProfile as r, AgentProfileRegistry as s, type AgentProfileType as t, type AgentStartData as u, type AgentStopData as v, type AgentToolLoopContext as w, type AgentToolLoopIterationGenerator as x, type AgentToolLoopIterationResult as y, type AgentToolLoopScript as z };
|