@lunora/agent 1.0.0-alpha.1 → 1.0.0-alpha.10
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 +2 -0
- package/dist/channels.d.mts +42 -22
- package/dist/channels.d.ts +42 -22
- package/dist/channels.mjs +1 -1
- package/dist/component.d.mts +59 -56
- package/dist/component.d.ts +59 -56
- package/dist/component.mjs +20 -9
- package/dist/inbound.d.mts +21 -16
- package/dist/inbound.d.ts +21 -16
- package/dist/index.d.mts +500 -408
- package/dist/index.d.ts +500 -408
- package/dist/index.mjs +6 -6
- package/dist/naming.d.mts +23 -10
- package/dist/naming.d.ts +23 -10
- package/dist/packem_shared/{VoiceSessionDO-DLoXsHGF.mjs → VoiceSessionDO-BdwlLaXC.mjs} +2 -2
- package/dist/packem_shared/{agentAsTool-Dt8NlU6k.mjs → agentAsTool-CUHlWsmt.mjs} +5 -1
- package/dist/packem_shared/{braintrustTelemetry-wuGDErob.mjs → braintrustTelemetry-TP7Kwuuj.mjs} +1 -1
- package/dist/packem_shared/{common-DAeFCot5.mjs → common-DQXayow6.mjs} +29 -1
- package/dist/packem_shared/compileAgentWorkflow-DYFFyx7i.mjs +78 -0
- package/dist/packem_shared/{consoleTelemetry-z2MiP1jt.mjs → consoleTelemetry--3sWfu1R.mjs} +1 -1
- package/dist/packem_shared/{createAgentGenerate-BQv9YJ01.mjs → createAgentGenerate-DO7Z96zX.mjs} +1 -1
- package/dist/packem_shared/{defineAgent-D6maSbVc.mjs → defineAgent-DAwAZC9P.mjs} +1 -1
- package/dist/packem_shared/{graph-component-aoUwO-f0.mjs → graph-component-Bbaxxymp.mjs} +3 -2
- package/dist/packem_shared/{normalizeEntityName-CyEEWFkR.mjs → normalizeEntityName-BouctxLC.mjs} +1 -1
- package/dist/packem_shared/otlpTelemetry-DU5ZmoEV.mjs +177 -0
- package/dist/packem_shared/{runAgentLoop-Dhg4ZNvw.mjs → runAgentLoop-M8PKbtWT.mjs} +2 -2
- package/dist/packem_shared/{sentryTelemetry-CgqFJyLO.mjs → sentryTelemetry-A4F5ndh9.mjs} +1 -1
- package/dist/packem_shared/types.d-boAM2Yi1.d.mts +1114 -0
- package/dist/packem_shared/types.d-boAM2Yi1.d.ts +1114 -0
- package/dist/sandbox.d.mts +129 -110
- package/dist/sandbox.d.ts +129 -110
- package/dist/sandbox.mjs +5 -1
- package/dist/telemetry/index.d.mts +190 -86
- package/dist/telemetry/index.d.ts +190 -86
- package/dist/telemetry/index.mjs +4 -3
- package/package.json +8 -8
- package/dist/packem_shared/compileAgentWorkflow-BxJjHgtD.mjs +0 -55
- package/dist/packem_shared/types.d-BWG0uUtX.d.mts +0 -1015
- package/dist/packem_shared/types.d-BWG0uUtX.d.ts +0 -1015
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export { runAgentLoop, splitForCompaction } from './packem_shared/runAgentLoop-
|
|
1
|
+
export { runAgentLoop, splitForCompaction } from './packem_shared/runAgentLoop-M8PKbtWT.mjs';
|
|
2
2
|
export { collectAgenticMemoryTools, toSearchResults } from './packem_shared/collectAgenticMemoryTools-QrzpV-WX.mjs';
|
|
3
|
-
export { agentAsTool } from './packem_shared/agentAsTool-
|
|
3
|
+
export { agentAsTool } from './packem_shared/agentAsTool-CUHlWsmt.mjs';
|
|
4
4
|
export { codeTool } from './packem_shared/codeTool-CjgJOC9t.mjs';
|
|
5
5
|
export { agentComponent, agentExtension } from './component.mjs';
|
|
6
6
|
export { default as createAgentContext } from './packem_shared/createAgentContext-4xJGXNR4.mjs';
|
|
7
|
-
export { defineAgent, defineAgentTool, isAgentDefinition } from './packem_shared/defineAgent-
|
|
7
|
+
export { defineAgent, defineAgentTool, isAgentDefinition } from './packem_shared/defineAgent-DAwAZC9P.mjs';
|
|
8
8
|
export { functionTool } from './packem_shared/functionTool-D6lCa2jB.mjs';
|
|
9
|
-
export { createAgentGenerate, createEpisodeExtract, createGraphExtract, createStreamGenerate, resolveAgentModel } from './packem_shared/createAgentGenerate-
|
|
9
|
+
export { createAgentGenerate, createEpisodeExtract, createGraphExtract, createStreamGenerate, resolveAgentModel } from './packem_shared/createAgentGenerate-DO7Z96zX.mjs';
|
|
10
10
|
export { adaptMcpResult, mcpTools } from './packem_shared/adaptMcpResult-wtNMvLoP.mjs';
|
|
11
11
|
export { buildModelMessages } from './packem_shared/buildModelMessages-BWFigaoo.mjs';
|
|
12
12
|
export { agentBindingName, agentClassName, agentDefaultName, voiceBindingName, voiceClassName } from './naming.mjs';
|
|
13
13
|
export { AGENT_MODULE, DEFAULT_AGENT_FUNCTION_PATHS, SANDBOX_INVOKE_PATH, SANDBOX_MODULE, toFunctionReference } from './packem_shared/AGENT_MODULE-Dnt_-AAT.mjs';
|
|
14
14
|
export { browserTool, containerTool, fsTool } from './sandbox.mjs';
|
|
15
15
|
export { defineSkill, isSkillDefinition } from './packem_shared/defineSkill-Ctf_S-rz.mjs';
|
|
16
|
-
export { default as VoiceSessionDO } from './packem_shared/VoiceSessionDO-
|
|
16
|
+
export { default as VoiceSessionDO } from './packem_shared/VoiceSessionDO-BdwlLaXC.mjs';
|
|
17
17
|
export { runVoiceTurn } from './packem_shared/runVoiceTurn-LnqLvCRR.mjs';
|
|
18
|
-
export { default as compileAgentWorkflow } from './packem_shared/compileAgentWorkflow-
|
|
18
|
+
export { default as compileAgentWorkflow } from './packem_shared/compileAgentWorkflow-DYFFyx7i.mjs';
|
package/dist/naming.d.mts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* `support` → `SupportAgentWorkflow` — the generated WorkflowEntrypoint class name.
|
|
3
|
+
* @experimental
|
|
4
|
+
*/
|
|
2
5
|
declare const agentClassName: (exportName: string) => string;
|
|
3
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* `support` → `AGENT_SUPPORT` — the Cloudflare Workflows binding name.
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
4
10
|
declare const agentBindingName: (exportName: string) => string;
|
|
5
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* `supportBot` → `agent-support-bot` — the default deployed workflow name.
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
6
15
|
declare const agentDefaultName: (exportName: string) => string;
|
|
7
16
|
/**
|
|
8
|
-
* `support` → `SupportVoiceDO` — the generated voice-session Durable Object
|
|
9
|
-
* class name (a subclass of `VoiceSessionDO`). Distinct from the agent's
|
|
10
|
-
* `WorkflowEntrypoint` (`SupportAgentWorkflow`): the voice path is a
|
|
11
|
-
* hibernatable-WebSocket DO that runs the per-turn STT→LLM→TTS pipeline in-DO,
|
|
12
|
-
* NOT the replay-durable Workflow.
|
|
13
|
-
|
|
17
|
+
* `support` → `SupportVoiceDO` — the generated voice-session Durable Object
|
|
18
|
+
* class name (a subclass of `VoiceSessionDO`). Distinct from the agent's
|
|
19
|
+
* `WorkflowEntrypoint` (`SupportAgentWorkflow`): the voice path is a
|
|
20
|
+
* hibernatable-WebSocket DO that runs the per-turn STT→LLM→TTS pipeline in-DO,
|
|
21
|
+
* NOT the replay-durable Workflow.
|
|
22
|
+
* @experimental
|
|
23
|
+
*/
|
|
14
24
|
declare const voiceClassName: (exportName: string) => string;
|
|
15
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* `support` → `VOICE_SUPPORT` — the Cloudflare Durable Object binding name for the voice session.
|
|
27
|
+
* @experimental
|
|
28
|
+
*/
|
|
16
29
|
declare const voiceBindingName: (exportName: string) => string;
|
|
17
30
|
export { agentBindingName, agentClassName, agentDefaultName, voiceBindingName, voiceClassName };
|
package/dist/naming.d.ts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* `support` → `SupportAgentWorkflow` — the generated WorkflowEntrypoint class name.
|
|
3
|
+
* @experimental
|
|
4
|
+
*/
|
|
2
5
|
declare const agentClassName: (exportName: string) => string;
|
|
3
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* `support` → `AGENT_SUPPORT` — the Cloudflare Workflows binding name.
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
4
10
|
declare const agentBindingName: (exportName: string) => string;
|
|
5
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* `supportBot` → `agent-support-bot` — the default deployed workflow name.
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
6
15
|
declare const agentDefaultName: (exportName: string) => string;
|
|
7
16
|
/**
|
|
8
|
-
* `support` → `SupportVoiceDO` — the generated voice-session Durable Object
|
|
9
|
-
* class name (a subclass of `VoiceSessionDO`). Distinct from the agent's
|
|
10
|
-
* `WorkflowEntrypoint` (`SupportAgentWorkflow`): the voice path is a
|
|
11
|
-
* hibernatable-WebSocket DO that runs the per-turn STT→LLM→TTS pipeline in-DO,
|
|
12
|
-
* NOT the replay-durable Workflow.
|
|
13
|
-
|
|
17
|
+
* `support` → `SupportVoiceDO` — the generated voice-session Durable Object
|
|
18
|
+
* class name (a subclass of `VoiceSessionDO`). Distinct from the agent's
|
|
19
|
+
* `WorkflowEntrypoint` (`SupportAgentWorkflow`): the voice path is a
|
|
20
|
+
* hibernatable-WebSocket DO that runs the per-turn STT→LLM→TTS pipeline in-DO,
|
|
21
|
+
* NOT the replay-durable Workflow.
|
|
22
|
+
* @experimental
|
|
23
|
+
*/
|
|
14
24
|
declare const voiceClassName: (exportName: string) => string;
|
|
15
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* `support` → `VOICE_SUPPORT` — the Cloudflare Durable Object binding name for the voice session.
|
|
27
|
+
* @experimental
|
|
28
|
+
*/
|
|
16
29
|
declare const voiceBindingName: (exportName: string) => string;
|
|
17
30
|
export { agentBindingName, agentClassName, agentDefaultName, voiceBindingName, voiceClassName };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createAi } from '@lunora/ai';
|
|
2
2
|
import { c as createDispatchRunner } from './createDispatchRunner-DSbp_dph-ZHTtxy3f.mjs';
|
|
3
3
|
import { t as toBase64 } from './base64-BVwtgRJV.mjs';
|
|
4
|
-
import { createStreamGenerate } from './createAgentGenerate-
|
|
4
|
+
import { createStreamGenerate } from './createAgentGenerate-DO7Z96zX.mjs';
|
|
5
5
|
import { DEFAULT_AGENT_FUNCTION_PATHS, toFunctionReference } from './AGENT_MODULE-Dnt_-AAT.mjs';
|
|
6
6
|
import { parseIdentity, pcmToWav, readTranscriptionText, readSynthesisAudio, runVoiceTurn, toByteIterable } from './runVoiceTurn-LnqLvCRR.mjs';
|
|
7
7
|
|
|
@@ -30,7 +30,7 @@ class VoiceSessionDO {
|
|
|
30
30
|
this.agent = agent;
|
|
31
31
|
this.exportName = exportName;
|
|
32
32
|
this.paths = DEFAULT_AGENT_FUNCTION_PATHS;
|
|
33
|
-
this.ai = createAi({ binding: env["AI"] });
|
|
33
|
+
this.ai = createAi({ binding: env["AI"], env });
|
|
34
34
|
this.streamGenerate = createStreamGenerate(agent, env);
|
|
35
35
|
this.sttModel = agent.voice?.stt ?? DEFAULT_STT_MODEL;
|
|
36
36
|
this.ttsModel = agent.voice?.tts ?? DEFAULT_TTS_MODEL;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LunoraError } from '@lunora/errors';
|
|
2
2
|
import { jsonSchema } from 'ai';
|
|
3
|
+
import { isDuplicateInstanceError } from '../channels.mjs';
|
|
3
4
|
import { agentBindingName } from '../naming.mjs';
|
|
4
5
|
import { toFunctionReference, DEFAULT_AGENT_FUNCTION_PATHS } from './AGENT_MODULE-Dnt_-AAT.mjs';
|
|
5
6
|
|
|
@@ -64,7 +65,10 @@ const agentAsTool = (options) => {
|
|
|
64
65
|
try {
|
|
65
66
|
const handle = await binding.create({ id: childInstanceId, params });
|
|
66
67
|
instance = await binding.get(handle.id);
|
|
67
|
-
} catch {
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (!isDuplicateInstanceError(error)) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
68
72
|
instance = await binding.get(childInstanceId);
|
|
69
73
|
}
|
|
70
74
|
const terminal = await pollUntilTerminal(instance, maxPolls, pollIntervalMs, wait);
|
package/dist/packem_shared/{braintrustTelemetry-wuGDErob.mjs → braintrustTelemetry-TP7Kwuuj.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as describeError, t as toolInputOf, r as readField } from './common-
|
|
1
|
+
import { d as describeError, t as toolInputOf, r as readField } from './common-DQXayow6.mjs';
|
|
2
2
|
|
|
3
3
|
const stringOr = (value, fallback) => typeof value === "string" && value.length > 0 ? value : fallback;
|
|
4
4
|
const braintrustTelemetry = (options) => {
|
|
@@ -14,6 +14,34 @@ const summarizeUsage = (usage) => {
|
|
|
14
14
|
}
|
|
15
15
|
return Object.keys(summary).length > 0 ? summary : void 0;
|
|
16
16
|
};
|
|
17
|
+
const summarizeGatewayTelemetry = (result) => {
|
|
18
|
+
const gateway = readField(readField(result, "providerMetadata"), "gateway");
|
|
19
|
+
const headers = readField(readField(result, "response"), "headers");
|
|
20
|
+
const readHeader = (name) => {
|
|
21
|
+
const getter = readField(headers, "get");
|
|
22
|
+
const value = typeof getter === "function" ? getter.call(headers, name) : readField(headers, name);
|
|
23
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
24
|
+
};
|
|
25
|
+
const summary = {};
|
|
26
|
+
const cost = readField(gateway, "cost");
|
|
27
|
+
if (typeof cost === "number" && Number.isFinite(cost)) {
|
|
28
|
+
summary.cost = cost;
|
|
29
|
+
}
|
|
30
|
+
const cachedField = readField(gateway, "cached");
|
|
31
|
+
const cacheStatusField = readField(gateway, "cacheStatus");
|
|
32
|
+
const cacheStatus = typeof cacheStatusField === "string" ? cacheStatusField : readHeader("cf-aig-cache-status");
|
|
33
|
+
if (typeof cachedField === "boolean") {
|
|
34
|
+
summary.cached = cachedField;
|
|
35
|
+
} else if (typeof cacheStatus === "string") {
|
|
36
|
+
summary.cached = cacheStatus.toUpperCase() === "HIT";
|
|
37
|
+
}
|
|
38
|
+
const metadataLogId = readField(gateway, "logId") ?? readField(gateway, "log_id");
|
|
39
|
+
const logId = typeof metadataLogId === "string" && metadataLogId.length > 0 ? metadataLogId : readHeader("cf-aig-log-id");
|
|
40
|
+
if (typeof logId === "string" && logId.length > 0) {
|
|
41
|
+
summary.logId = logId;
|
|
42
|
+
}
|
|
43
|
+
return Object.keys(summary).length > 0 ? summary : void 0;
|
|
44
|
+
};
|
|
17
45
|
const describeToolOutcome = (event) => {
|
|
18
46
|
const toolCall = readField(event, "toolCall");
|
|
19
47
|
const nameValue = readField(toolCall, "toolName");
|
|
@@ -58,4 +86,4 @@ const describeError = (error) => {
|
|
|
58
86
|
return error;
|
|
59
87
|
};
|
|
60
88
|
|
|
61
|
-
export { toolNameOf as a, describeToolOutcome as b, contentText as c, describeError as d, readField as r, summarizeUsage as s, toolInputOf as t };
|
|
89
|
+
export { toolNameOf as a, describeToolOutcome as b, contentText as c, describeError as d, summarizeGatewayTelemetry as e, readField as r, summarizeUsage as s, toolInputOf as t };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { defineWorkflow } from '@lunora/workflow';
|
|
2
|
+
import { runAgentLoop } from './runAgentLoop-M8PKbtWT.mjs';
|
|
3
|
+
import { createStreamGenerate, createAgentGenerate, createEpisodeExtract, createGraphExtract, createCompact } from './createAgentGenerate-DO7Z96zX.mjs';
|
|
4
|
+
import { agentDefaultName } from '../naming.mjs';
|
|
5
|
+
import { DEFAULT_AGENT_FUNCTION_PATHS } from './AGENT_MODULE-Dnt_-AAT.mjs';
|
|
6
|
+
import { c as createDispatchRunner } from './createDispatchRunner-DSbp_dph-ZHTtxy3f.mjs';
|
|
7
|
+
import { otlpTelemetry } from './otlpTelemetry-DU5ZmoEV.mjs';
|
|
8
|
+
|
|
9
|
+
const resolveAgentRun = (contextRun, owner, env) => {
|
|
10
|
+
if (owner === void 0) {
|
|
11
|
+
return contextRun;
|
|
12
|
+
}
|
|
13
|
+
return createDispatchRunner({ env, identity: { userId: owner }, label: "@lunora/agent" });
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const withAutoOtlpTelemetry = (agent, env, conversationId) => {
|
|
17
|
+
const endpoint = env.LUNORA_OTLP_ENDPOINT;
|
|
18
|
+
if (typeof endpoint !== "string" || endpoint === "" || agent.telemetry?.isEnabled === false) {
|
|
19
|
+
return agent;
|
|
20
|
+
}
|
|
21
|
+
const token = typeof env.LUNORA_OTLP_TOKEN === "string" ? env.LUNORA_OTLP_TOKEN : void 0;
|
|
22
|
+
const existingList = [agent.telemetry?.integrations].flat().filter((integration) => integration !== void 0);
|
|
23
|
+
return {
|
|
24
|
+
...agent,
|
|
25
|
+
telemetry: {
|
|
26
|
+
...agent.telemetry,
|
|
27
|
+
// Tag every generation span with the run's thread as its conversation
|
|
28
|
+
// id (one thread = one multi-turn conversation), so the cloud groups a
|
|
29
|
+
// deployed agent's turns with no app wiring. Absent → ungrouped, as before.
|
|
30
|
+
integrations: [...existingList, otlpTelemetry({ conversationId, endpoint, token })],
|
|
31
|
+
isEnabled: true
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const compileAgentWorkflow = (agent, exportName, options) => defineWorkflow({
|
|
36
|
+
handler: async (context) => {
|
|
37
|
+
const runtimeAgent = withAutoOtlpTelemetry(agent, context.env, context.params.threadKey);
|
|
38
|
+
return runAgentLoop({
|
|
39
|
+
agent: runtimeAgent,
|
|
40
|
+
// Automatic history compaction. Dormant unless the agent declares
|
|
41
|
+
// a `compaction` config; the loop gates on it, so any other agent
|
|
42
|
+
// takes the byte-identical no-compaction path.
|
|
43
|
+
compact: createCompact(),
|
|
44
|
+
env: context.env,
|
|
45
|
+
exportName,
|
|
46
|
+
// Run-end graph extraction. Dormant unless the agent declares a
|
|
47
|
+
// `kind: "graph"` memory source AND the run carries an owner — the
|
|
48
|
+
// loop gates on both, so a semantic-only agent takes the
|
|
49
|
+
// byte-identical no-extraction path.
|
|
50
|
+
extractGraph: createGraphExtract(),
|
|
51
|
+
// Run-end episode recording. Dormant unless the agent declares a
|
|
52
|
+
// `kind: "episodic"` memory source AND the run carries an owner —
|
|
53
|
+
// the loop gates on both, so any other agent is byte-identical.
|
|
54
|
+
extractEpisode: createEpisodeExtract(),
|
|
55
|
+
generate: createAgentGenerate(runtimeAgent, context.env),
|
|
56
|
+
instanceId: context.event.instanceId,
|
|
57
|
+
params: context.params,
|
|
58
|
+
paths: options?.paths ?? DEFAULT_AGENT_FUNCTION_PATHS,
|
|
59
|
+
// The loop reads its own owner-gated thread back through
|
|
60
|
+
// `agents:*` queries. The default `context.run` forwards no
|
|
61
|
+
// identity, so on an OWNED thread those reads would come back
|
|
62
|
+
// empty and the model would answer blind. `resolveAgentRun`
|
|
63
|
+
// dispatches an owner-scoped run under that verified identity so
|
|
64
|
+
// the owner gate admits the loop's reads (ownerless runs keep the
|
|
65
|
+
// identity-free `context.run`). See `resolve-run.ts`.
|
|
66
|
+
run: resolveAgentRun(context.run, context.params.owner, context.env),
|
|
67
|
+
step: context.step,
|
|
68
|
+
// The streaming seam is wired and ready, but stays dormant until a
|
|
69
|
+
// live token sink is threaded onto the run (a follow-up wires
|
|
70
|
+
// `onTokenDelta` to the stream transport). With no sink the loop
|
|
71
|
+
// takes the byte-identical non-streaming `generate` path.
|
|
72
|
+
streamGenerate: createStreamGenerate(runtimeAgent, context.env)
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
name: agent.name ?? agentDefaultName(exportName)
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export { compileAgentWorkflow as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as summarizeUsage, c as contentText, t as toolInputOf, d as describeError, r as readField, a as toolNameOf, b as describeToolOutcome } from './common-
|
|
1
|
+
import { s as summarizeUsage, c as contentText, t as toolInputOf, d as describeError, r as readField, a as toolNameOf, b as describeToolOutcome } from './common-DQXayow6.mjs';
|
|
2
2
|
|
|
3
3
|
const defaultLogger = (level, message, fields) => {
|
|
4
4
|
const target = globalThis.console;
|
package/dist/packem_shared/{createAgentGenerate-BQv9YJ01.mjs → createAgentGenerate-DO7Z96zX.mjs}
RENAMED
|
@@ -33,7 +33,7 @@ const resolveAgentModel = (model, env) => {
|
|
|
33
33
|
`@lunora/agent: the agent model "${model}" is a Workers AI id but there is no \`AI\` binding on the workflow env — declare the ai binding in wrangler.jsonc`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
-
return createAi({ binding }).model(model);
|
|
36
|
+
return createAi({ binding, env }).model(model);
|
|
37
37
|
}
|
|
38
38
|
return model;
|
|
39
39
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LunoraError } from '@lunora/errors';
|
|
2
2
|
import { collectAgenticMemoryTools } from './collectAgenticMemoryTools-QrzpV-WX.mjs';
|
|
3
|
-
import { agentAsTool } from './agentAsTool-
|
|
3
|
+
import { agentAsTool } from './agentAsTool-CUHlWsmt.mjs';
|
|
4
4
|
import { i as isInjectedMemorySource } from './memory-D4FPcBsX.mjs';
|
|
5
5
|
import { SKILL_NAME_PATTERN, RESERVED_SKILL_NAME } from './defineSkill-Ctf_S-rz.mjs';
|
|
6
6
|
|
|
@@ -34,7 +34,7 @@ const graphTables = {
|
|
|
34
34
|
type: v.optional(v.string()),
|
|
35
35
|
updatedAt: v.number(),
|
|
36
36
|
weight: v.optional(v.number())
|
|
37
|
-
}).index("byOwnerName", ["owner", "name"], { unique: true }).public(),
|
|
37
|
+
}).index("byOwnerName", ["owner", "name"], { unique: true }).index("byOwnerUpdatedAt", ["owner", "updatedAt"]).public(),
|
|
38
38
|
/**
|
|
39
39
|
* Graph-memory edges — directed triples storing the normalized endpoint
|
|
40
40
|
* NAMES (no join on write), owner-scoped like the nodes. `weight` is
|
|
@@ -57,6 +57,7 @@ const DEFAULT_GRAPH_DEPTH = 2;
|
|
|
57
57
|
const DEFAULT_GRAPH_MAX_SEEDS = 4;
|
|
58
58
|
const DEFAULT_GRAPH_FAN_OUT = 8;
|
|
59
59
|
const DEFAULT_GRAPH_MAX_NODES = 32;
|
|
60
|
+
const GRAPH_SEED_SCAN_CAP = 500;
|
|
60
61
|
const WHITESPACE_RUN = /\s+/gu;
|
|
61
62
|
const NON_WORD = /[^\p{L}\p{N}]+/u;
|
|
62
63
|
const normalizeEntityName = (name) => name.trim().replaceAll(WHITESPACE_RUN, " ").toLowerCase();
|
|
@@ -186,7 +187,7 @@ const graphComponent = () => {
|
|
|
186
187
|
if (tokens.length === 0) {
|
|
187
188
|
return { context: "" };
|
|
188
189
|
}
|
|
189
|
-
const ownerEntities = await context.db.query(ENTITIES_TABLE).withIndex("
|
|
190
|
+
const ownerEntities = await context.db.query(ENTITIES_TABLE).withIndex("byOwnerUpdatedAt", (q) => q.eq("owner", args.owner)).order("desc").take(GRAPH_SEED_SCAN_CAP);
|
|
190
191
|
const seeds = ownerEntities.filter((row) => matchesSeed(row["name"], tokens)).toSorted(
|
|
191
192
|
(a, b) => (b["weight"] ?? 1) - (a["weight"] ?? 1) || a["name"].localeCompare(b["name"])
|
|
192
193
|
).slice(0, args.maxSeeds ?? DEFAULT_GRAPH_MAX_SEEDS).map((row) => row["name"]);
|
package/dist/packem_shared/{normalizeEntityName-CyEEWFkR.mjs → normalizeEntityName-BouctxLC.mjs}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import '@lunora/server';
|
|
2
2
|
import '@lunora/values';
|
|
3
|
-
export { b as graphComponent, g as graphTables, n as normalizeEntityName } from './graph-component-
|
|
3
|
+
export { b as graphComponent, g as graphTables, n as normalizeEntityName } from './graph-component-Bbaxxymp.mjs';
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { s as summarizeUsage, r as readField, e as summarizeGatewayTelemetry, c as contentText, t as toolInputOf, a as toolNameOf } from './common-DQXayow6.mjs';
|
|
2
|
+
|
|
3
|
+
const otlpUnixNano = (ms) => `${String(Math.round(ms))}000000`;
|
|
4
|
+
const otlpRandomHex = (bytes) => {
|
|
5
|
+
const buffer = new Uint8Array(bytes);
|
|
6
|
+
crypto.getRandomValues(buffer);
|
|
7
|
+
let hex = "";
|
|
8
|
+
for (const byte of buffer) {
|
|
9
|
+
hex += byte.toString(16).padStart(2, "0");
|
|
10
|
+
}
|
|
11
|
+
return hex;
|
|
12
|
+
};
|
|
13
|
+
const encodeAttribute = (key, value) => {
|
|
14
|
+
if (typeof value === "boolean") {
|
|
15
|
+
return { key, value: { boolValue: value } };
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === "number") {
|
|
18
|
+
if (!Number.isFinite(value)) {
|
|
19
|
+
return { key, value: { stringValue: String(value) } };
|
|
20
|
+
}
|
|
21
|
+
return Number.isSafeInteger(value) ? { key, value: { intValue: String(value) } } : { key, value: { doubleValue: value } };
|
|
22
|
+
}
|
|
23
|
+
return { key, value: { stringValue: value } };
|
|
24
|
+
};
|
|
25
|
+
const mergeHeaders = (defaults, overrides, token) => {
|
|
26
|
+
const merged = {};
|
|
27
|
+
const seen = /* @__PURE__ */ new Map();
|
|
28
|
+
const put = (name, value) => {
|
|
29
|
+
const lower = name.toLowerCase();
|
|
30
|
+
const existing = seen.get(lower);
|
|
31
|
+
if (existing === void 0) {
|
|
32
|
+
seen.set(lower, name);
|
|
33
|
+
merged[name] = value;
|
|
34
|
+
} else {
|
|
35
|
+
merged[existing] = value;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
for (const [name, value] of Object.entries(defaults)) {
|
|
39
|
+
put(name, value);
|
|
40
|
+
}
|
|
41
|
+
for (const [name, value] of Object.entries(overrides ?? {})) {
|
|
42
|
+
put(name, value);
|
|
43
|
+
}
|
|
44
|
+
if (token !== void 0 && token.length > 0) {
|
|
45
|
+
put("authorization", `Bearer ${token}`);
|
|
46
|
+
}
|
|
47
|
+
return merged;
|
|
48
|
+
};
|
|
49
|
+
const buildResourceAttributes = (serviceName, extra) => {
|
|
50
|
+
const merged = { "service.name": serviceName };
|
|
51
|
+
for (const [key, value] of Object.entries({})) {
|
|
52
|
+
merged[key] = value;
|
|
53
|
+
}
|
|
54
|
+
return Object.entries(merged).map(([key, value]) => encodeAttribute(key, value));
|
|
55
|
+
};
|
|
56
|
+
const wrapResourceSpans = (span, scopeName, serviceName, resourceAttributes) => {
|
|
57
|
+
return {
|
|
58
|
+
resourceSpans: [
|
|
59
|
+
{
|
|
60
|
+
resource: { attributes: buildResourceAttributes(serviceName) },
|
|
61
|
+
scopeSpans: [{ scope: { name: scopeName }, spans: [span] }]
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const pushAttribute = (attributes, key, value) => {
|
|
68
|
+
if (value === void 0 || value === null) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
|
|
72
|
+
attributes.push(encodeAttribute(key, value));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
attributes.push(encodeAttribute(key, JSON.stringify(value)));
|
|
76
|
+
};
|
|
77
|
+
const observeSettled = (promise, onSettle) => {
|
|
78
|
+
const run = async () => {
|
|
79
|
+
let result;
|
|
80
|
+
try {
|
|
81
|
+
result = await promise;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
onSettle(false, error instanceof Error ? error.message : String(error), void 0);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
onSettle(true, void 0, result);
|
|
87
|
+
};
|
|
88
|
+
run().catch(() => void 0);
|
|
89
|
+
};
|
|
90
|
+
const otlpTelemetry = (options) => {
|
|
91
|
+
const { conversationId, endpoint, headers, recordInputs = false, recordOutputs = false, token, traceId: fixedTraceId, waitUntil } = options;
|
|
92
|
+
const serviceName = options.serviceName ?? "lunora";
|
|
93
|
+
let base = endpoint;
|
|
94
|
+
while (base.endsWith("/")) {
|
|
95
|
+
base = base.slice(0, -1);
|
|
96
|
+
}
|
|
97
|
+
const tracesUrl = `${base}/v1/traces`;
|
|
98
|
+
const mergedHeaders = mergeHeaders({ "content-type": "application/json" }, headers, token);
|
|
99
|
+
const emitSpan = (name, startTs, ok, message, attributes) => {
|
|
100
|
+
const span = {
|
|
101
|
+
attributes,
|
|
102
|
+
endTimeUnixNano: otlpUnixNano(Date.now()),
|
|
103
|
+
// SPAN_KIND_INTERNAL — matches the runtime's `ctx.trace` spans.
|
|
104
|
+
kind: 1,
|
|
105
|
+
name,
|
|
106
|
+
spanId: otlpRandomHex(8),
|
|
107
|
+
startTimeUnixNano: otlpUnixNano(startTs),
|
|
108
|
+
// STATUS_CODE_OK (1) / STATUS_CODE_ERROR (2).
|
|
109
|
+
status: ok ? { code: 1 } : { code: 2, message: message ?? "" },
|
|
110
|
+
traceId: fixedTraceId ?? otlpRandomHex(16)
|
|
111
|
+
};
|
|
112
|
+
try {
|
|
113
|
+
const sent = fetch(tracesUrl, {
|
|
114
|
+
body: JSON.stringify(wrapResourceSpans(span, "@lunora/agent", serviceName)),
|
|
115
|
+
headers: mergedHeaders,
|
|
116
|
+
method: "POST"
|
|
117
|
+
}).catch(() => {
|
|
118
|
+
});
|
|
119
|
+
waitUntil?.(sent);
|
|
120
|
+
} catch {
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
executeLanguageModelCall: (options_) => {
|
|
125
|
+
const startTs = Date.now();
|
|
126
|
+
const modelId = readField(options_, "modelId");
|
|
127
|
+
const promise = options_.execute();
|
|
128
|
+
const emit = (ok, message, result) => {
|
|
129
|
+
const attributes = [];
|
|
130
|
+
pushAttribute(attributes, "gen_ai.operation.name", "chat");
|
|
131
|
+
pushAttribute(attributes, "gen_ai.request.model", modelId);
|
|
132
|
+
pushAttribute(attributes, "gen_ai.system", readField(options_, "provider"));
|
|
133
|
+
pushAttribute(attributes, "gen_ai.conversation.id", conversationId);
|
|
134
|
+
const usage = summarizeUsage(readField(result, "usage"));
|
|
135
|
+
if (usage) {
|
|
136
|
+
pushAttribute(attributes, "gen_ai.usage.input_tokens", usage.inputTokens);
|
|
137
|
+
pushAttribute(attributes, "gen_ai.usage.output_tokens", usage.outputTokens);
|
|
138
|
+
pushAttribute(attributes, "gen_ai.usage.total_tokens", usage.totalTokens);
|
|
139
|
+
}
|
|
140
|
+
const gateway = summarizeGatewayTelemetry(result);
|
|
141
|
+
if (gateway) {
|
|
142
|
+
pushAttribute(attributes, "gen_ai.usage.cost", gateway.cost);
|
|
143
|
+
pushAttribute(attributes, "gen_ai.response.cached", gateway.cached);
|
|
144
|
+
pushAttribute(attributes, "cf.aig.log_id", gateway.logId);
|
|
145
|
+
}
|
|
146
|
+
if (recordInputs) {
|
|
147
|
+
pushAttribute(attributes, "gen_ai.prompt", readField(options_, "messages"));
|
|
148
|
+
}
|
|
149
|
+
if (recordOutputs) {
|
|
150
|
+
pushAttribute(attributes, "gen_ai.completion", contentText(readField(result, "content")));
|
|
151
|
+
}
|
|
152
|
+
emitSpan(typeof modelId === "string" ? `chat ${modelId}` : "language_model_call", startTs, ok, message, attributes);
|
|
153
|
+
};
|
|
154
|
+
observeSettled(promise, emit);
|
|
155
|
+
return promise;
|
|
156
|
+
},
|
|
157
|
+
executeTool: (options_) => {
|
|
158
|
+
const startTs = Date.now();
|
|
159
|
+
const toolName = toolNameOf(options_);
|
|
160
|
+
const promise = options_.execute();
|
|
161
|
+
const emit = (ok, message) => {
|
|
162
|
+
const attributes = [];
|
|
163
|
+
pushAttribute(attributes, "gen_ai.operation.name", "execute_tool");
|
|
164
|
+
pushAttribute(attributes, "gen_ai.tool.name", toolName);
|
|
165
|
+
pushAttribute(attributes, "gen_ai.tool.call.id", readField(options_, "toolCallId"));
|
|
166
|
+
if (recordInputs) {
|
|
167
|
+
pushAttribute(attributes, "gen_ai.tool.input", toolInputOf(options_));
|
|
168
|
+
}
|
|
169
|
+
emitSpan(typeof toolName === "string" ? `execute_tool ${toolName}` : "execute_tool", startTs, ok, message, attributes);
|
|
170
|
+
};
|
|
171
|
+
observeSettled(promise, emit);
|
|
172
|
+
return promise;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export { otlpTelemetry };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveAgentModel } from './createAgentGenerate-
|
|
1
|
+
import { resolveAgentModel } from './createAgentGenerate-DO7Z96zX.mjs';
|
|
2
2
|
import { f as firstGraphSource, m as memoryStepName, a as firstEpisodicSource, r as resolveInjectedSources } from './memory-D4FPcBsX.mjs';
|
|
3
3
|
import { buildModelMessages } from './buildModelMessages-BWFigaoo.mjs';
|
|
4
4
|
import { agentBindingName } from '../naming.mjs';
|
|
@@ -63,7 +63,7 @@ const awaitApproval = async (turnContext, call) => {
|
|
|
63
63
|
toolName: call.name
|
|
64
64
|
});
|
|
65
65
|
await patchThread({ status: "awaiting_input" });
|
|
66
|
-
const event = await step.waitForEvent(`approval:${call.id}`, { type:
|
|
66
|
+
const event = await step.waitForEvent(`approval:${call.id}`, { type: `agent-approval:${call.id}` });
|
|
67
67
|
await patchThread({ status: "running" });
|
|
68
68
|
return { decision: event.payload.decision, ...event.payload.note === void 0 ? {} : { note: event.payload.note } };
|
|
69
69
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as readField, t as toolInputOf } from './common-
|
|
1
|
+
import { r as readField, t as toolInputOf } from './common-DQXayow6.mjs';
|
|
2
2
|
|
|
3
3
|
const stringOr = (value, fallback) => typeof value === "string" && value.length > 0 ? value : fallback;
|
|
4
4
|
const sentryTelemetry = (options) => {
|