@framers/agentos 0.12.12 → 0.12.14
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 +1 -1
- package/dist/api/agency.d.ts.map +1 -1
- package/dist/api/agency.js +26 -5
- package/dist/api/agency.js.map +1 -1
- package/dist/api/agent.d.ts +35 -1
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js +8 -0
- package/dist/api/agent.js.map +1 -1
- package/dist/api/gmi.d.ts +21 -0
- package/dist/api/gmi.d.ts.map +1 -0
- package/dist/api/gmi.js +527 -0
- package/dist/api/gmi.js.map +1 -0
- package/dist/api/hitl.d.ts +3 -2
- package/dist/api/hitl.d.ts.map +1 -1
- package/dist/api/hitl.js +8 -2
- package/dist/api/hitl.js.map +1 -1
- package/dist/api/runtime/agentCognitiveMemory.d.ts +82 -0
- package/dist/api/runtime/agentCognitiveMemory.d.ts.map +1 -0
- package/dist/api/runtime/agentCognitiveMemory.js +277 -0
- package/dist/api/runtime/agentCognitiveMemory.js.map +1 -0
- package/dist/api/runtime/approval-gate.d.ts +13 -8
- package/dist/api/runtime/approval-gate.d.ts.map +1 -1
- package/dist/api/runtime/approval-gate.js +75 -25
- package/dist/api/runtime/approval-gate.js.map +1 -1
- package/dist/api/runtime/capabilityContract.d.ts +21 -1
- package/dist/api/runtime/capabilityContract.d.ts.map +1 -1
- package/dist/api/runtime/capabilityContract.js +15 -15
- package/dist/api/runtime/capabilityContract.js.map +1 -1
- package/dist/api/runtime/gmiCognition.d.ts +66 -0
- package/dist/api/runtime/gmiCognition.d.ts.map +1 -0
- package/dist/api/runtime/gmiCognition.js +58 -0
- package/dist/api/runtime/gmiCognition.js.map +1 -0
- package/dist/api/runtime/gmiPersona.d.ts +16 -0
- package/dist/api/runtime/gmiPersona.d.ts.map +1 -0
- package/dist/api/runtime/gmiPersona.js +91 -0
- package/dist/api/runtime/gmiPersona.js.map +1 -0
- package/dist/api/runtime/gmiResults.d.ts +98 -0
- package/dist/api/runtime/gmiResults.d.ts.map +1 -0
- package/dist/api/runtime/gmiResults.js +333 -0
- package/dist/api/runtime/gmiResults.js.map +1 -0
- package/dist/api/runtime/gmiSession.d.ts +85 -0
- package/dist/api/runtime/gmiSession.d.ts.map +1 -0
- package/dist/api/runtime/gmiSession.js +285 -0
- package/dist/api/runtime/gmiSession.js.map +1 -0
- package/dist/api/runtime/gmiTranscript.d.ts +48 -0
- package/dist/api/runtime/gmiTranscript.d.ts.map +1 -0
- package/dist/api/runtime/gmiTranscript.js +110 -0
- package/dist/api/runtime/gmiTranscript.js.map +1 -0
- package/dist/api/runtime/lightweightAgentDiagnostics.d.ts +6 -1
- package/dist/api/runtime/lightweightAgentDiagnostics.d.ts.map +1 -1
- package/dist/api/runtime/lightweightAgentDiagnostics.js +9 -2
- package/dist/api/runtime/lightweightAgentDiagnostics.js.map +1 -1
- package/dist/api/runtime/tool-emulation/loop.d.ts +5 -0
- package/dist/api/runtime/tool-emulation/loop.d.ts.map +1 -1
- package/dist/api/runtime/tool-emulation/loop.js +4 -4
- package/dist/api/runtime/tool-emulation/loop.js.map +1 -1
- package/dist/api/sessionHistory.d.ts +43 -1
- package/dist/api/sessionHistory.d.ts.map +1 -1
- package/dist/api/sessionHistory.js +56 -1
- package/dist/api/sessionHistory.js.map +1 -1
- package/dist/api/sessionTranscript.d.ts +8 -0
- package/dist/api/sessionTranscript.d.ts.map +1 -1
- package/dist/api/sessionTranscript.js.map +1 -1
- package/dist/api/transferStyle.d.ts +8 -0
- package/dist/api/transferStyle.d.ts.map +1 -1
- package/dist/api/transferStyle.js +4 -1
- package/dist/api/transferStyle.js.map +1 -1
- package/dist/api/types.d.ts +32 -12
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js.map +1 -1
- package/dist/cognition/substrate/GMI.d.ts.map +1 -1
- package/dist/cognition/substrate/GMI.js +54 -2
- package/dist/cognition/substrate/GMI.js.map +1 -1
- package/dist/cognition/substrate/IGMI.d.ts +23 -1
- package/dist/cognition/substrate/IGMI.d.ts.map +1 -1
- package/dist/cognition/substrate/IGMI.js.map +1 -1
- package/dist/io/vision/VisionPipeline.d.ts +5 -0
- package/dist/io/vision/VisionPipeline.d.ts.map +1 -1
- package/dist/io/vision/VisionPipeline.js +28 -13
- package/dist/io/vision/VisionPipeline.js.map +1 -1
- package/dist/io/vision/index.d.ts.map +1 -1
- package/dist/io/vision/index.js +2 -0
- package/dist/io/vision/index.js.map +1 -1
- package/dist/io/vision/types.d.ts +11 -0
- package/dist/io/vision/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file agentCognitiveMemory.ts
|
|
3
|
+
* Cognitive memory for GMIs built from agent options (`agent({ runtime: 'gmi' })`,
|
|
4
|
+
* spec D7): a {@link CognitiveMemoryManager} over an in-memory vector store, the
|
|
5
|
+
* in-memory knowledge graph, an embedding manager for `memory.embedding`, a
|
|
6
|
+
* working memory of its own and the persona's HEXACO traits.
|
|
7
|
+
*
|
|
8
|
+
* One manager serves every session of an agent. Each GMI's memory bridge passes
|
|
9
|
+
* the session's mood on every encode, retrieve and assemble call and scopes
|
|
10
|
+
* recall to the session's user and conversation, so the manager's own mood
|
|
11
|
+
* callback is neutral. The memory graph runs on the `'knowledge-graph'` backend
|
|
12
|
+
* over the same in-memory knowledge graph, because the `'graphology'` backend
|
|
13
|
+
* needs graphology, an optional peer dependency. Consolidation runs only when
|
|
14
|
+
* `memory.consolidation.enabled` is true. The build embeds one test text through
|
|
15
|
+
* the embedding model it sets up, so a model that cannot answer, or answers with
|
|
16
|
+
* another size than memory expects, fails the build instead of leaving memory empty.
|
|
17
|
+
*/
|
|
18
|
+
import { CognitiveMemoryManager } from '../../cognition/memory/CognitiveMemoryManager.js';
|
|
19
|
+
import type { CognitiveMechanismsConfig } from '../../cognition/memory/mechanisms/types.js';
|
|
20
|
+
import type { IPersonaDefinition } from '../../cognition/substrate/personas/IPersonaDefinition.js';
|
|
21
|
+
import type { IEmbeddingManager } from '../../core/embeddings/IEmbeddingManager.js';
|
|
22
|
+
import type { MemoryConfig } from '../types.js';
|
|
23
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
24
|
+
/**
|
|
25
|
+
* Checks, when the agent is built, that cognitive memory has an embedding model
|
|
26
|
+
* it can use, so a missing or unusable one fails before the first send. Reads
|
|
27
|
+
* the environment only to pick the provider when `memory.embedding` is unset;
|
|
28
|
+
* credentials are read when the memory is built.
|
|
29
|
+
*
|
|
30
|
+
* @param memory - The agent's memory config.
|
|
31
|
+
* @param env - The environment to read OPENAI_API_KEY and OLLAMA_BASE_URL from (defaults to `process.env`).
|
|
32
|
+
* @throws {Error} Naming `memory.embedding` when no provider is set or detected, when the
|
|
33
|
+
* provider has no embeddings (Anthropic, Groq, xAI, the Claude Code and Gemini CLIs), when the
|
|
34
|
+
* model does not resolve, or when the model's output size is unknown and
|
|
35
|
+
* `memory.embedding.dimension` is unset or not a positive integer.
|
|
36
|
+
*/
|
|
37
|
+
export declare function assertEmbeddingAvailable(memory: MemoryConfig, env?: Env): void;
|
|
38
|
+
/**
|
|
39
|
+
* The checks on `memory.embedding` that read no environment, for `gmi()` to run
|
|
40
|
+
* when the agent is built: with a provider set, that it has embeddings, that the
|
|
41
|
+
* model resolves on it, that a declared dimension is a positive integer, and that
|
|
42
|
+
* the model's output size is known or declared. With no provider set, the
|
|
43
|
+
* provider is picked from the environment when the memory is first built, and
|
|
44
|
+
* only a declared dimension is checked here.
|
|
45
|
+
*
|
|
46
|
+
* @param memory - The agent's memory config.
|
|
47
|
+
* @throws {Error} Naming `memory.embedding`, as {@link assertEmbeddingAvailable} does.
|
|
48
|
+
*/
|
|
49
|
+
export declare function assertEmbeddingConfig(memory: MemoryConfig): void;
|
|
50
|
+
export interface AgentCognitiveMemoryOptions {
|
|
51
|
+
/** The agent's persona: its id is the memory's owner (`agentId`), its traits shape encoding. */
|
|
52
|
+
persona: IPersonaDefinition;
|
|
53
|
+
memory: MemoryConfig;
|
|
54
|
+
/** The memory mechanisms to run; none when undefined. */
|
|
55
|
+
mechanisms?: CognitiveMechanismsConfig;
|
|
56
|
+
/**
|
|
57
|
+
* An embedding manager to use instead of one built from `memory.embedding`
|
|
58
|
+
* (tests, and hosts that own one). The caller keeps ownership: `close()` does not shut it down.
|
|
59
|
+
*/
|
|
60
|
+
embeddingManager?: IEmbeddingManager;
|
|
61
|
+
}
|
|
62
|
+
export interface AgentCognitiveMemory {
|
|
63
|
+
manager: CognitiveMemoryManager;
|
|
64
|
+
/**
|
|
65
|
+
* Shuts the manager down and releases the vector store and the embedding
|
|
66
|
+
* manager this builder created. Later calls return the first call's promise.
|
|
67
|
+
*/
|
|
68
|
+
close(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Builds and initialises the cognitive memory manager an agent's GMIs share.
|
|
72
|
+
*
|
|
73
|
+
* @param opts - The persona, the memory config, the mechanisms and an optional embedding manager.
|
|
74
|
+
* @returns The manager and a `close()` that releases it.
|
|
75
|
+
* @throws {Error} When the embedding model is missing or unusable (see {@link assertEmbeddingAvailable}),
|
|
76
|
+
* when its provider has no credentials or fails to start, when a test embedding through it
|
|
77
|
+
* fails or returns another size than memory expects (skipped for an embedding manager the
|
|
78
|
+
* caller passes), or when the manager fails to initialise.
|
|
79
|
+
*/
|
|
80
|
+
export declare function createAgentCognitiveMemory(opts: AgentCognitiveMemoryOptions): Promise<AgentCognitiveMemory>;
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=agentCognitiveMemory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentCognitiveMemory.d.ts","sourceRoot":"","sources":["../../../src/api/runtime/agentCognitiveMemory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAE1F,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAM5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0DAA0D,CAAC;AAEnG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAGpF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA+BhD,KAAK,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AA4ExD;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,GAAE,GAAiB,GAAG,IAAI,CAE3F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAMhE;AAED,MAAM,WAAW,2BAA2B;IAC1C,gGAAgG;IAChG,OAAO,EAAE,kBAAkB,CAAC;IAC5B,MAAM,EAAE,YAAY,CAAC;IACrB,yDAAyD;IACzD,UAAU,CAAC,EAAE,yBAAyB,CAAC;IACvC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;CACtC;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,sBAAsB,CAAC;IAChC;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAgFD;;;;;;;;;GASG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,2BAA2B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAgEjH"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file agentCognitiveMemory.ts
|
|
3
|
+
* Cognitive memory for GMIs built from agent options (`agent({ runtime: 'gmi' })`,
|
|
4
|
+
* spec D7): a {@link CognitiveMemoryManager} over an in-memory vector store, the
|
|
5
|
+
* in-memory knowledge graph, an embedding manager for `memory.embedding`, a
|
|
6
|
+
* working memory of its own and the persona's HEXACO traits.
|
|
7
|
+
*
|
|
8
|
+
* One manager serves every session of an agent. Each GMI's memory bridge passes
|
|
9
|
+
* the session's mood on every encode, retrieve and assemble call and scopes
|
|
10
|
+
* recall to the session's user and conversation, so the manager's own mood
|
|
11
|
+
* callback is neutral. The memory graph runs on the `'knowledge-graph'` backend
|
|
12
|
+
* over the same in-memory knowledge graph, because the `'graphology'` backend
|
|
13
|
+
* needs graphology, an optional peer dependency. Consolidation runs only when
|
|
14
|
+
* `memory.consolidation.enabled` is true. The build embeds one test text through
|
|
15
|
+
* the embedding model it sets up, so a model that cannot answer, or answers with
|
|
16
|
+
* another size than memory expects, fails the build instead of leaving memory empty.
|
|
17
|
+
*/
|
|
18
|
+
import { CognitiveMemoryManager } from '../../cognition/memory/CognitiveMemoryManager.js';
|
|
19
|
+
import { KnowledgeGraph } from '../../cognition/memory/retrieval/graph/knowledge/KnowledgeGraph.js';
|
|
20
|
+
import { EmbeddingManager } from '../../cognition/rag/EmbeddingManager.js';
|
|
21
|
+
import { InMemoryVectorStore } from '../../cognition/rag/vector_stores/InMemoryVectorStore.js';
|
|
22
|
+
import { InMemoryWorkingMemory } from '../../cognition/substrate/memory/InMemoryWorkingMemory.js';
|
|
23
|
+
import { HEXACO_TRAIT_KEYS, normalizeHexacoTraits } from '../../cognition/substrate/personas/hexaco.js';
|
|
24
|
+
import { createProviderManager, resolveModelOption, resolveProvider } from '../model.js';
|
|
25
|
+
/**
|
|
26
|
+
* Output sizes of the embedding models agentos knows, as each returns them when
|
|
27
|
+
* no `dimensions` is requested: OpenAI's (text-embedding-3 in
|
|
28
|
+
* https://developers.openai.com/api/docs/guides/embeddings; all three as
|
|
29
|
+
* OpenAIProvider records them for its model listing), nomic-embed-text's
|
|
30
|
+
* (https://huggingface.co/nomic-ai/nomic-embed-text-v1.5) and Gemini's (the
|
|
31
|
+
* sizes GeminiProvider's catalog records).
|
|
32
|
+
*/
|
|
33
|
+
const KNOWN_EMBEDDING_DIMENSIONS = new Map([
|
|
34
|
+
['text-embedding-3-small', 1536],
|
|
35
|
+
['text-embedding-3-large', 3072],
|
|
36
|
+
['text-embedding-ada-002', 1536],
|
|
37
|
+
['nomic-embed-text', 768],
|
|
38
|
+
['gemini-embedding-001', 3072],
|
|
39
|
+
['gemini-embedding-2', 3072],
|
|
40
|
+
]);
|
|
41
|
+
/** Providers whose agentos implementation has no embeddings: their `generateEmbeddings` always throws. */
|
|
42
|
+
const PROVIDERS_WITHOUT_EMBEDDINGS = new Map([
|
|
43
|
+
['anthropic', 'Anthropic'],
|
|
44
|
+
['groq', 'Groq'],
|
|
45
|
+
['xai', 'xAI'],
|
|
46
|
+
['claude-code-cli', 'The Claude Code CLI'],
|
|
47
|
+
['gemini-cli', 'The Gemini CLI'],
|
|
48
|
+
]);
|
|
49
|
+
const NEUTRAL_PAD = { valence: 0, arousal: 0, dominance: 0 };
|
|
50
|
+
function messageOf(error) {
|
|
51
|
+
return error instanceof Error ? error.message : String(error);
|
|
52
|
+
}
|
|
53
|
+
/** An Error carrying the error it reports as `cause`. */
|
|
54
|
+
function errorWithCause(message, cause) {
|
|
55
|
+
return Object.assign(new Error(message), { cause });
|
|
56
|
+
}
|
|
57
|
+
function refuseProviderWithoutEmbeddings(providerId) {
|
|
58
|
+
const label = PROVIDERS_WITHOUT_EMBEDDINGS.get(providerId.toLowerCase());
|
|
59
|
+
if (label) {
|
|
60
|
+
throw new Error(`gmi(): ${label} has no embedding models in agentos; set memory.embedding to a provider that has them, such as openai or ollama.`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** The size of a model in {@link KNOWN_EMBEDDING_DIMENSIONS}, also under a vendor prefix (`openai/...`) or an Ollama tag (`...:latest`). */
|
|
64
|
+
function knownDimension(modelId) {
|
|
65
|
+
const exact = KNOWN_EMBEDDING_DIMENSIONS.get(modelId);
|
|
66
|
+
if (exact !== undefined)
|
|
67
|
+
return exact;
|
|
68
|
+
const base = modelId.slice(modelId.lastIndexOf('/') + 1).split(':')[0];
|
|
69
|
+
return KNOWN_EMBEDDING_DIMENSIONS.get(base);
|
|
70
|
+
}
|
|
71
|
+
/** `memory.embedding.dimension`, refused when it is set and is not a positive integer. */
|
|
72
|
+
function checkedDimension(memory) {
|
|
73
|
+
const declared = memory.embedding?.dimension;
|
|
74
|
+
if (declared !== undefined && !(Number.isInteger(declared) && declared > 0)) {
|
|
75
|
+
throw new Error(`gmi(): memory.embedding.dimension must be a positive integer; got ${String(declared)}.`);
|
|
76
|
+
}
|
|
77
|
+
return declared;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolves the embedding model from `memory.embedding`, or, when it is unset,
|
|
81
|
+
* from the environment: OpenAI's default embedding model when OPENAI_API_KEY is
|
|
82
|
+
* set, else Ollama's when OLLAMA_BASE_URL is set. Only checks whether those two
|
|
83
|
+
* are set; the provider's credentials are resolved when the memory is built.
|
|
84
|
+
*/
|
|
85
|
+
function resolveEmbeddingTarget(memory, env) {
|
|
86
|
+
const requested = memory.embedding?.provider || (env.OPENAI_API_KEY ? 'openai' : env.OLLAMA_BASE_URL ? 'ollama' : undefined);
|
|
87
|
+
if (!requested) {
|
|
88
|
+
throw new Error('gmi(): cognitive memory needs an embedding model. Set memory.embedding: { provider, model } or set OPENAI_API_KEY or OLLAMA_BASE_URL.');
|
|
89
|
+
}
|
|
90
|
+
refuseProviderWithoutEmbeddings(requested);
|
|
91
|
+
let model;
|
|
92
|
+
try {
|
|
93
|
+
model = resolveModelOption({ provider: requested, model: memory.embedding?.model }, 'embedding');
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
throw errorWithCause(`gmi(): memory.embedding: ${messageOf(error)}`, error);
|
|
97
|
+
}
|
|
98
|
+
// A `provider:model` id names its own provider, which may be one that cannot embed.
|
|
99
|
+
refuseProviderWithoutEmbeddings(model.providerId);
|
|
100
|
+
const declared = checkedDimension(memory);
|
|
101
|
+
const dimension = declared ?? knownDimension(model.modelId);
|
|
102
|
+
if (dimension === undefined) {
|
|
103
|
+
throw new Error(`gmi(): set memory.embedding.dimension for the embedding model '${model.modelId}'; agentos does not know its output size.`);
|
|
104
|
+
}
|
|
105
|
+
return { ...model, dimension };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Checks, when the agent is built, that cognitive memory has an embedding model
|
|
109
|
+
* it can use, so a missing or unusable one fails before the first send. Reads
|
|
110
|
+
* the environment only to pick the provider when `memory.embedding` is unset;
|
|
111
|
+
* credentials are read when the memory is built.
|
|
112
|
+
*
|
|
113
|
+
* @param memory - The agent's memory config.
|
|
114
|
+
* @param env - The environment to read OPENAI_API_KEY and OLLAMA_BASE_URL from (defaults to `process.env`).
|
|
115
|
+
* @throws {Error} Naming `memory.embedding` when no provider is set or detected, when the
|
|
116
|
+
* provider has no embeddings (Anthropic, Groq, xAI, the Claude Code and Gemini CLIs), when the
|
|
117
|
+
* model does not resolve, or when the model's output size is unknown and
|
|
118
|
+
* `memory.embedding.dimension` is unset or not a positive integer.
|
|
119
|
+
*/
|
|
120
|
+
export function assertEmbeddingAvailable(memory, env = process.env) {
|
|
121
|
+
resolveEmbeddingTarget(memory, env);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The checks on `memory.embedding` that read no environment, for `gmi()` to run
|
|
125
|
+
* when the agent is built: with a provider set, that it has embeddings, that the
|
|
126
|
+
* model resolves on it, that a declared dimension is a positive integer, and that
|
|
127
|
+
* the model's output size is known or declared. With no provider set, the
|
|
128
|
+
* provider is picked from the environment when the memory is first built, and
|
|
129
|
+
* only a declared dimension is checked here.
|
|
130
|
+
*
|
|
131
|
+
* @param memory - The agent's memory config.
|
|
132
|
+
* @throws {Error} Naming `memory.embedding`, as {@link assertEmbeddingAvailable} does.
|
|
133
|
+
*/
|
|
134
|
+
export function assertEmbeddingConfig(memory) {
|
|
135
|
+
if (memory.embedding?.provider) {
|
|
136
|
+
resolveEmbeddingTarget(memory, {});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
checkedDimension(memory);
|
|
140
|
+
}
|
|
141
|
+
/** The text the build embeds once to check the embedding model. */
|
|
142
|
+
const PROBE_TEXT = 'cognitive memory embedding check';
|
|
143
|
+
/**
|
|
144
|
+
* Embeds {@link PROBE_TEXT} once through the provider and model the embedding
|
|
145
|
+
* manager will call, and fails when the model cannot answer (an Ollama model
|
|
146
|
+
* that was never pulled, a model the provider does not serve) or answers with
|
|
147
|
+
* another size than memory expects. Without this check the build succeeds and
|
|
148
|
+
* memory stays empty: the embedding manager drops each failed or wrong-size
|
|
149
|
+
* vector, the memory store refuses the trace, and the GMI's memory bridge only
|
|
150
|
+
* records a trace warning.
|
|
151
|
+
*
|
|
152
|
+
* @param provider - The provider the embedding manager will call.
|
|
153
|
+
* @param model - The resolved provider and model.
|
|
154
|
+
* @param expected - The vector size memory expects.
|
|
155
|
+
* @param declared - `memory.embedding.dimension`, when set.
|
|
156
|
+
*/
|
|
157
|
+
async function probeEmbeddingModel(provider, model, expected, declared) {
|
|
158
|
+
const label = `cognitive memory's embedding model '${model.modelId}' on ${model.providerId}`;
|
|
159
|
+
let response;
|
|
160
|
+
try {
|
|
161
|
+
response = await provider.generateEmbeddings(model.modelId, [PROBE_TEXT]);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
throw errorWithCause(`gmi(): ${label} failed a test call (memory.embedding): ${messageOf(error)}`, error);
|
|
165
|
+
}
|
|
166
|
+
if (response?.error) {
|
|
167
|
+
throw errorWithCause(`gmi(): ${label} failed a test call (memory.embedding): ${response.error.message}`, response.error);
|
|
168
|
+
}
|
|
169
|
+
const vector = response?.data?.[0]?.embedding;
|
|
170
|
+
const size = Array.isArray(vector) ? vector.length : 0;
|
|
171
|
+
if (size === 0) {
|
|
172
|
+
throw new Error(`gmi(): ${label} returned no vector for a test call (memory.embedding).`);
|
|
173
|
+
}
|
|
174
|
+
if (size !== expected) {
|
|
175
|
+
const expectation = declared !== undefined
|
|
176
|
+
? `memory.embedding.dimension (${declared}) declares ${declared}`
|
|
177
|
+
: `agentos expects ${expected} for this model`;
|
|
178
|
+
throw new Error(`gmi(): ${label} returns ${size} values, while ${expectation}; set memory.embedding.dimension to ${size}.`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async function buildEmbeddingManager(memory) {
|
|
182
|
+
const target = resolveEmbeddingTarget(memory, process.env);
|
|
183
|
+
let resolved;
|
|
184
|
+
let providerManager;
|
|
185
|
+
try {
|
|
186
|
+
resolved = resolveProvider(target.providerId, target.modelId);
|
|
187
|
+
providerManager = await createProviderManager(resolved);
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
// The chat model may run on the same provider with other credentials; name the memory's.
|
|
191
|
+
throw errorWithCause(`gmi(): cognitive memory could not start its embedding provider '${target.providerId}' (memory.embedding): ${messageOf(error)}`, error);
|
|
192
|
+
}
|
|
193
|
+
const provider = providerManager.getProvider(resolved.providerId);
|
|
194
|
+
if (!provider) {
|
|
195
|
+
throw new Error(`gmi(): cognitive memory's embedding provider '${resolved.providerId}' is not available (memory.embedding).`);
|
|
196
|
+
}
|
|
197
|
+
await probeEmbeddingModel(provider, resolved, target.dimension, memory.embedding?.dimension);
|
|
198
|
+
const manager = new EmbeddingManager();
|
|
199
|
+
await manager.initialize({
|
|
200
|
+
embeddingModels: [{ modelId: resolved.modelId, providerId: resolved.providerId, dimension: target.dimension, isDefault: true }],
|
|
201
|
+
defaultModelId: resolved.modelId,
|
|
202
|
+
enableCache: true,
|
|
203
|
+
}, providerManager);
|
|
204
|
+
return { manager, dimension: target.dimension };
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Builds and initialises the cognitive memory manager an agent's GMIs share.
|
|
208
|
+
*
|
|
209
|
+
* @param opts - The persona, the memory config, the mechanisms and an optional embedding manager.
|
|
210
|
+
* @returns The manager and a `close()` that releases it.
|
|
211
|
+
* @throws {Error} When the embedding model is missing or unusable (see {@link assertEmbeddingAvailable}),
|
|
212
|
+
* when its provider has no credentials or fails to start, when a test embedding through it
|
|
213
|
+
* fails or returns another size than memory expects (skipped for an embedding manager the
|
|
214
|
+
* caller passes), or when the manager fails to initialise.
|
|
215
|
+
*/
|
|
216
|
+
export async function createAgentCognitiveMemory(opts) {
|
|
217
|
+
const owned = opts.embeddingManager === undefined;
|
|
218
|
+
const embedding = opts.embeddingManager
|
|
219
|
+
? { manager: opts.embeddingManager, dimension: await opts.embeddingManager.getEmbeddingDimension() }
|
|
220
|
+
: await buildEmbeddingManager(opts.memory);
|
|
221
|
+
const storeId = `gmi-memory-${opts.persona.id}`;
|
|
222
|
+
const vectorStoreConfig = {
|
|
223
|
+
id: storeId,
|
|
224
|
+
type: 'in_memory',
|
|
225
|
+
similarityMetric: 'cosine',
|
|
226
|
+
defaultEmbeddingDimension: embedding.dimension,
|
|
227
|
+
};
|
|
228
|
+
const vectorStore = new InMemoryVectorStore();
|
|
229
|
+
await vectorStore.initialize(vectorStoreConfig);
|
|
230
|
+
const knowledgeGraph = new KnowledgeGraph();
|
|
231
|
+
await knowledgeGraph.initialize();
|
|
232
|
+
const workingMemory = new InMemoryWorkingMemory();
|
|
233
|
+
await workingMemory.initialize(storeId);
|
|
234
|
+
// Canonical trait names (honestyHumility reads as honesty); 0.5 for a trait the persona leaves out.
|
|
235
|
+
const declared = normalizeHexacoTraits(opts.persona.personalityTraits);
|
|
236
|
+
const traits = {};
|
|
237
|
+
for (const key of HEXACO_TRAIT_KEYS)
|
|
238
|
+
traits[key] = declared[key] ?? 0.5;
|
|
239
|
+
const consolidationEnabled = opts.memory.consolidation?.enabled === true;
|
|
240
|
+
if (consolidationEnabled && opts.memory.consolidation?.interval) {
|
|
241
|
+
console.warn(`[agentos] gmi(): memory.consolidation.interval ('${opts.memory.consolidation.interval}') is not applied; consolidation runs every hour.`);
|
|
242
|
+
}
|
|
243
|
+
const config = {
|
|
244
|
+
workingMemory,
|
|
245
|
+
knowledgeGraph,
|
|
246
|
+
vectorStore,
|
|
247
|
+
embeddingManager: embedding.manager,
|
|
248
|
+
agentId: opts.persona.id,
|
|
249
|
+
traits,
|
|
250
|
+
moodProvider: () => ({ ...NEUTRAL_PAD }),
|
|
251
|
+
featureDetectionStrategy: 'keyword',
|
|
252
|
+
graph: { backend: 'knowledge-graph' },
|
|
253
|
+
...(opts.mechanisms ? { cognitiveMechanisms: opts.mechanisms } : {}),
|
|
254
|
+
consolidation: { enabled: consolidationEnabled },
|
|
255
|
+
};
|
|
256
|
+
const manager = new CognitiveMemoryManager();
|
|
257
|
+
await manager.initialize(config);
|
|
258
|
+
let closing;
|
|
259
|
+
return {
|
|
260
|
+
manager,
|
|
261
|
+
close: () => (closing ?? (closing = (async () => {
|
|
262
|
+
try {
|
|
263
|
+
await manager.shutdown();
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
try {
|
|
267
|
+
await vectorStore.shutdown();
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
if (owned)
|
|
271
|
+
await embedding.manager.shutdown?.();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
})())),
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=agentCognitiveMemory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentCognitiveMemory.js","sourceRoot":"","sources":["../../../src/api/runtime/agentCognitiveMemory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAG1F,OAAO,EAAE,cAAc,EAAE,MAAM,oEAAoE,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0DAA0D,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,2DAA2D,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAOxG,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,e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,EAAE,EAAE,CAAC;gBAClD,CAAC;YACH,CAAC;QACH,CAAC,CAAC,EAAE,EAAC;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
* tool loops of `generateText` and `streamText` and the prompt-tool shim call
|
|
6
6
|
* it after `onBeforeToolExecution`, on the arguments that hook left. It never
|
|
7
7
|
* throws: a rejection, a handler error, a timeout, a guardrail block and a
|
|
8
|
-
* received gate that threw all skip the tool. A handler error
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* received gate that threw all skip the tool. A handler error (a throw, an
|
|
9
|
+
* answer whose `approved` is not a boolean, or a failure after the handler
|
|
10
|
+
* answered) or an `onTimeout: 'error'` timeout is stored in the owner's slot,
|
|
11
|
+
* which `agency()` checks when its strategy settles; the model is told only
|
|
12
|
+
* that the approval handler failed, and the error itself goes to the slot and
|
|
13
|
+
* `on.error`.
|
|
11
14
|
*/
|
|
12
15
|
import type { AgencyOptions, ApprovalDecision, ApprovalRequest } from '../types.js';
|
|
13
16
|
/**
|
|
@@ -76,11 +79,13 @@ export interface CreateApprovalGateOptions {
|
|
|
76
79
|
* (or every tool, for `'*'`), the handler is asked through
|
|
77
80
|
* {@link resolveApprovalDecision}; an approved decision runs the post-approval
|
|
78
81
|
* guardrails over the arguments unless `hitl.guardrailOverride` is `false`.
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
82
|
+
* An approval that carries `modifications.toolArgs` (anything but `undefined`
|
|
83
|
+
* or `null`) is refused: the gate never applies other arguments, so the call
|
|
84
|
+
* is skipped rather than run with the ones the approver meant to replace.
|
|
85
|
+
* Argument rewriting belongs to `onBeforeToolExecution`, which ran first.
|
|
86
|
+
* Once the slot holds an error (the call will reject) or its owner has
|
|
87
|
+
* settled, the gate skips every tool without asking the handler or firing
|
|
88
|
+
* approval events; after settlement it also drops any later error.
|
|
84
89
|
*/
|
|
85
90
|
export declare function createApprovalGate(o: CreateApprovalGateOptions): ApprovalGateFn;
|
|
86
91
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-gate.d.ts","sourceRoot":"","sources":["../../../src/api/runtime/approval-gate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"approval-gate.d.ts","sourceRoot":"","sources":["../../../src/api/runtime/approval-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGpF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAAoD,CAAC;AAE3F,+DAA+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,kEAAkE;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gEAAgE;AAChE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,kCAAkC;AAClC,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,gBAAgB,GAAG,eAAe,CAAC,CAAC;AAE5G,gHAAgH;AAChH,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,yDAAyD;AACzD,wBAAgB,kBAAkB,IAAI,YAAY,CAEjD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAI9E;AAqCD;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,EAC9C,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,gBAAgB,CAAC,CA4B3B;AAED,6CAA6C;AAC7C,MAAM,WAAW,yBAAyB;IACxC,kFAAkF;IAClF,IAAI,EAAE,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,sFAAsF;IACtF,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;IACxB,+DAA+D;IAC/D,IAAI,EAAE,YAAY,CAAC;IACnB,qGAAqG;IACrG,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,yBAAyB,GAAG,cAAc,CAmG/E;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,gBAAgB,GAAG,eAAe,CAAC,CAOtI"}
|
|
@@ -24,6 +24,15 @@ export function composeReceivedGate(value) {
|
|
|
24
24
|
return async () => refusal('the received approval gate is not a function');
|
|
25
25
|
}
|
|
26
26
|
const refusal = (reason) => ({ skipped: true, reason });
|
|
27
|
+
/**
|
|
28
|
+
* What the model is told when the handler fails or an `'error'` timeout
|
|
29
|
+
* fires. Fixed, because an error's message can name a URL or a credential
|
|
30
|
+
* (fetch's for a webhook URL that carries one does), and the refusal reason
|
|
31
|
+
* is sent to the model provider as the tool result.
|
|
32
|
+
*/
|
|
33
|
+
const HANDLER_FAILED = 'the approval handler failed';
|
|
34
|
+
/** Why an approval that names other arguments is refused: the gate approves or refuses, and never applies them. */
|
|
35
|
+
const TOOL_ARGS_NOT_APPLIED = 'the arguments the approval names (modifications.toolArgs) are not applied; rewrite them in onBeforeToolExecution';
|
|
27
36
|
/** Anything but the exact approval is a refusal; a refusal keeps its own string reason. */
|
|
28
37
|
function asVerdict(verdict, fallback) {
|
|
29
38
|
if (verdict === APPROVAL_GRANTED)
|
|
@@ -33,6 +42,10 @@ function asVerdict(verdict, fallback) {
|
|
|
33
42
|
: fallback;
|
|
34
43
|
return refusal(reason);
|
|
35
44
|
}
|
|
45
|
+
/** Whether a handler's answer is a decision: an object whose `approved` is a boolean. */
|
|
46
|
+
function isDecision(answer) {
|
|
47
|
+
return answer !== null && typeof answer === 'object' && typeof answer.approved === 'boolean';
|
|
48
|
+
}
|
|
36
49
|
function safeCall(fn, event) {
|
|
37
50
|
try {
|
|
38
51
|
fn?.(event);
|
|
@@ -83,11 +96,13 @@ export async function resolveApprovalDecision(hitlConfig, request) {
|
|
|
83
96
|
* (or every tool, for `'*'`), the handler is asked through
|
|
84
97
|
* {@link resolveApprovalDecision}; an approved decision runs the post-approval
|
|
85
98
|
* guardrails over the arguments unless `hitl.guardrailOverride` is `false`.
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
99
|
+
* An approval that carries `modifications.toolArgs` (anything but `undefined`
|
|
100
|
+
* or `null`) is refused: the gate never applies other arguments, so the call
|
|
101
|
+
* is skipped rather than run with the ones the approver meant to replace.
|
|
102
|
+
* Argument rewriting belongs to `onBeforeToolExecution`, which ran first.
|
|
103
|
+
* Once the slot holds an error (the call will reject) or its owner has
|
|
104
|
+
* settled, the gate skips every tool without asking the handler or firing
|
|
105
|
+
* approval events; after settlement it also drops any later error.
|
|
91
106
|
*/
|
|
92
107
|
export function createApprovalGate(o) {
|
|
93
108
|
const listed = o.hitl.approvals?.beforeTool ?? [];
|
|
@@ -116,6 +131,11 @@ export function createApprovalGate(o) {
|
|
|
116
131
|
const parent = asVerdict(verdict, 'not approved by the parent agency');
|
|
117
132
|
if (parent !== APPROVAL_GRANTED)
|
|
118
133
|
return parent;
|
|
134
|
+
// The parent's approval can arrive after this call ended (a concurrent
|
|
135
|
+
// approval failed, or the owner settled): it runs nothing and asks no one.
|
|
136
|
+
const afterParent = stopped();
|
|
137
|
+
if (afterParent)
|
|
138
|
+
return afterParent;
|
|
119
139
|
}
|
|
120
140
|
if (!covers(info.name))
|
|
121
141
|
return APPROVAL_GRANTED;
|
|
@@ -129,40 +149,70 @@ export function createApprovalGate(o) {
|
|
|
129
149
|
context: { agentCalls: [], totalTokens: 0, totalCostUSD: 0, elapsedMs: 0 },
|
|
130
150
|
};
|
|
131
151
|
safeCall(o.on?.approvalRequested, request);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
152
|
+
/**
|
|
153
|
+
* A handler error. Before settlement the first is stored in the slot and
|
|
154
|
+
* each one goes to `on.error`; the model is told only that the handler
|
|
155
|
+
* failed.
|
|
156
|
+
*/
|
|
157
|
+
const failed = (err) => {
|
|
137
158
|
if (!o.slot.settled) {
|
|
138
159
|
// A rejection with no reason still fails the call.
|
|
139
160
|
if (o.slot.error === undefined)
|
|
140
161
|
o.slot.error = err === undefined ? new AgencyConfigError('HITL approval failed') : err;
|
|
141
162
|
safeCall(o.on?.error, { agent: o.agentName, error: err instanceof Error ? err : new Error(String(err)), timestamp: Date.now() });
|
|
142
163
|
}
|
|
143
|
-
return refusal(
|
|
164
|
+
return refusal(HANDLER_FAILED);
|
|
165
|
+
};
|
|
166
|
+
let decision;
|
|
167
|
+
try {
|
|
168
|
+
const answer = await resolveApprovalDecision(o.hitl, request);
|
|
169
|
+
// An answer whose `approved` is not a boolean (a webhook that answers
|
|
170
|
+
// `null`, a string) is a handler error, never an approval.
|
|
171
|
+
if (!isDecision(answer))
|
|
172
|
+
throw new AgencyConfigError('HITL handler returned a malformed decision: approved must be a boolean');
|
|
173
|
+
decision = answer;
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
return failed(err);
|
|
144
177
|
}
|
|
145
178
|
// A decision that arrives after the call ended (a concurrent approval
|
|
146
179
|
// failed, or the owner settled) fires nothing and runs nothing.
|
|
147
180
|
const late = stopped();
|
|
148
181
|
if (late)
|
|
149
182
|
return late;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
183
|
+
try {
|
|
184
|
+
safeCall(o.on?.approvalDecided, decision);
|
|
185
|
+
if (!decision.approved)
|
|
186
|
+
return refusal(decision.reason ?? 'rejected by the approval handler');
|
|
187
|
+
// Arguments are rewritten in onBeforeToolExecution, never by a decision:
|
|
188
|
+
// an approval that names other arguments is refused, so the call never
|
|
189
|
+
// runs with the ones the approver meant to replace.
|
|
190
|
+
if (decision.modifications?.toolArgs != null)
|
|
191
|
+
return refusal(TOOL_ARGS_NOT_APPLIED);
|
|
192
|
+
if (o.hitl.guardrailOverride !== false) {
|
|
193
|
+
const { runPostApprovalGuardrails } = await import('../agency.js');
|
|
194
|
+
// The import yields, and the guardrails fire their events as soon as
|
|
195
|
+
// they run: a call that ended meanwhile runs none of them.
|
|
196
|
+
const beforeGuardrails = stopped();
|
|
197
|
+
if (beforeGuardrails)
|
|
198
|
+
return beforeGuardrails;
|
|
199
|
+
const result = await runPostApprovalGuardrails(info.name, info.args, o.hitl.postApprovalGuardrails ?? ['pii-redaction', 'code-safety'], o.on);
|
|
200
|
+
// The guardrail check is awaited: a call that ended meanwhile fires nothing.
|
|
201
|
+
const afterGuardrails = stopped();
|
|
202
|
+
if (afterGuardrails)
|
|
203
|
+
return afterGuardrails;
|
|
204
|
+
if (!result.passed) {
|
|
205
|
+
safeCall(o.on?.guardrailHitlOverride, { guardrailId: result.guardrailId, reason: result.reason, toolName: info.name, timestamp: Date.now() });
|
|
206
|
+
return refusal(`guardrail ${result.guardrailId}: ${result.reason}`);
|
|
207
|
+
}
|
|
163
208
|
}
|
|
209
|
+
return stopped() ?? APPROVAL_GRANTED;
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
// A failure after the handler answered (arguments the guardrails cannot
|
|
213
|
+
// serialize, such as a BigInt a hook added) is a handler error too.
|
|
214
|
+
return failed(err);
|
|
164
215
|
}
|
|
165
|
-
return stopped() ?? APPROVAL_GRANTED;
|
|
166
216
|
};
|
|
167
217
|
}
|
|
168
218
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-gate.js","sourceRoot":"","sources":["../../../src/api/runtime/approval-gate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"approval-gate.js","sourceRoot":"","sources":["../../../src/api/runtime/approval-gate.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkB,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AA6B3F,yDAAyD;AACzD,MAAM,UAAU,kBAAkB;IAChC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,OAAO,KAAK,KAAK,UAAU;QAAE,OAAO,KAAuB,CAAC;IAChE,OAAO,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,8CAA8C,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,OAAO,GAAG,CAAC,MAAc,EAAmB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD,mHAAmH;AACnH,MAAM,qBAAqB,GAAG,kHAAkH,CAAC;AAEjJ,2FAA2F;AAC3F,SAAS,SAAS,CAAC,OAAgB,EAAE,QAAgB;IACnD,IAA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