@dexto/core 1.6.25 → 1.6.27

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.
Files changed (150) hide show
  1. package/dist/agent/DextoAgent.cjs +102 -104
  2. package/dist/agent/DextoAgent.d.ts +11 -10
  3. package/dist/agent/DextoAgent.d.ts.map +1 -1
  4. package/dist/agent/DextoAgent.js +103 -105
  5. package/dist/agent/error-codes.cjs +1 -0
  6. package/dist/agent/error-codes.d.ts +1 -0
  7. package/dist/agent/error-codes.d.ts.map +1 -1
  8. package/dist/agent/error-codes.js +1 -0
  9. package/dist/agent/errors.cjs +13 -0
  10. package/dist/agent/errors.d.ts +6 -0
  11. package/dist/agent/errors.d.ts.map +1 -1
  12. package/dist/agent/errors.js +13 -0
  13. package/dist/agent/index.d.ts +1 -0
  14. package/dist/agent/index.d.ts.map +1 -1
  15. package/dist/agent/schemas.d.ts +2 -2
  16. package/dist/agent/types.d.ts +11 -0
  17. package/dist/agent/types.d.ts.map +1 -1
  18. package/dist/approval/factory.cjs +1 -0
  19. package/dist/approval/factory.d.ts.map +1 -1
  20. package/dist/approval/factory.js +1 -0
  21. package/dist/approval/manager.cjs +345 -182
  22. package/dist/approval/manager.d.ts +45 -31
  23. package/dist/approval/manager.d.ts.map +1 -1
  24. package/dist/approval/manager.js +345 -182
  25. package/dist/approval/schemas.cjs +10 -0
  26. package/dist/approval/schemas.d.ts +305 -0
  27. package/dist/approval/schemas.d.ts.map +1 -1
  28. package/dist/approval/schemas.js +10 -0
  29. package/dist/approval/session-approval-store.cjs +91 -0
  30. package/dist/approval/session-approval-store.d.ts +55 -0
  31. package/dist/approval/session-approval-store.d.ts.map +1 -0
  32. package/dist/approval/session-approval-store.js +68 -0
  33. package/dist/events/index.cjs +210 -75
  34. package/dist/events/index.d.ts +44 -181
  35. package/dist/events/index.d.ts.map +1 -1
  36. package/dist/events/index.js +206 -74
  37. package/dist/hooks/manager.cjs +5 -2
  38. package/dist/hooks/manager.d.ts +2 -0
  39. package/dist/hooks/manager.d.ts.map +1 -1
  40. package/dist/hooks/manager.js +5 -2
  41. package/dist/hooks/types.d.ts +3 -0
  42. package/dist/hooks/types.d.ts.map +1 -1
  43. package/dist/index.browser.d.ts +1 -0
  44. package/dist/index.browser.d.ts.map +1 -1
  45. package/dist/index.cjs +3 -1
  46. package/dist/index.d.ts +1 -0
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +1 -0
  49. package/dist/llm/executor/turn-executor.cjs +15 -7
  50. package/dist/llm/executor/turn-executor.d.ts +3 -1
  51. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  52. package/dist/llm/executor/turn-executor.js +15 -7
  53. package/dist/llm/services/factory.cjs +10 -4
  54. package/dist/llm/services/factory.d.ts +2 -21
  55. package/dist/llm/services/factory.d.ts.map +1 -1
  56. package/dist/llm/services/factory.js +11 -7
  57. package/dist/llm/services/types.d.ts +33 -2
  58. package/dist/llm/services/types.d.ts.map +1 -1
  59. package/dist/llm/services/vercel.cjs +33 -11
  60. package/dist/llm/services/vercel.d.ts +6 -3
  61. package/dist/llm/services/vercel.d.ts.map +1 -1
  62. package/dist/llm/services/vercel.js +29 -8
  63. package/dist/logger/default-logger-factory.d.ts +12 -12
  64. package/dist/logger/v2/schemas.d.ts +6 -6
  65. package/dist/mcp/manager.cjs +7 -2
  66. package/dist/mcp/manager.d.ts +3 -1
  67. package/dist/mcp/manager.d.ts.map +1 -1
  68. package/dist/mcp/manager.js +7 -2
  69. package/dist/mcp/mcp-client.cjs +71 -62
  70. package/dist/mcp/mcp-client.d.ts +3 -2
  71. package/dist/mcp/mcp-client.d.ts.map +1 -1
  72. package/dist/mcp/mcp-client.js +71 -62
  73. package/dist/mcp/schemas.d.ts +10 -10
  74. package/dist/resources/handlers/filesystem-handler.cjs +22 -3
  75. package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
  76. package/dist/resources/handlers/filesystem-handler.js +22 -3
  77. package/dist/runtime/host-runtime.cjs +163 -0
  78. package/dist/runtime/host-runtime.d.ts +23 -0
  79. package/dist/runtime/host-runtime.d.ts.map +1 -0
  80. package/dist/runtime/host-runtime.js +133 -0
  81. package/dist/runtime/index.cjs +42 -0
  82. package/dist/runtime/index.d.ts +2 -0
  83. package/dist/runtime/index.d.ts.map +1 -0
  84. package/dist/runtime/index.js +21 -0
  85. package/dist/runtime/run-context.cjs +53 -0
  86. package/dist/runtime/run-context.d.ts +13 -0
  87. package/dist/runtime/run-context.d.ts.map +1 -0
  88. package/dist/runtime/run-context.js +34 -0
  89. package/dist/session/chat-session.cjs +67 -71
  90. package/dist/session/chat-session.d.ts +25 -25
  91. package/dist/session/chat-session.d.ts.map +1 -1
  92. package/dist/session/chat-session.js +68 -72
  93. package/dist/session/error-codes.cjs +1 -0
  94. package/dist/session/error-codes.d.ts +2 -1
  95. package/dist/session/error-codes.d.ts.map +1 -1
  96. package/dist/session/error-codes.js +1 -0
  97. package/dist/session/errors.cjs +13 -0
  98. package/dist/session/errors.d.ts +6 -0
  99. package/dist/session/errors.d.ts.map +1 -1
  100. package/dist/session/errors.js +13 -0
  101. package/dist/session/message-queue-store.cjs +75 -0
  102. package/dist/session/message-queue-store.d.ts +16 -0
  103. package/dist/session/message-queue-store.d.ts.map +1 -0
  104. package/dist/session/message-queue-store.js +52 -0
  105. package/dist/session/message-queue.cjs +140 -46
  106. package/dist/session/message-queue.d.ts +18 -6
  107. package/dist/session/message-queue.d.ts.map +1 -1
  108. package/dist/session/message-queue.js +140 -46
  109. package/dist/session/session-manager.cjs +130 -25
  110. package/dist/session/session-manager.d.ts +18 -1
  111. package/dist/session/session-manager.d.ts.map +1 -1
  112. package/dist/session/session-manager.js +130 -25
  113. package/dist/session/title-generator.cjs +9 -2
  114. package/dist/session/title-generator.d.ts +2 -0
  115. package/dist/session/title-generator.d.ts.map +1 -1
  116. package/dist/session/title-generator.js +9 -2
  117. package/dist/telemetry/decorators.cjs +75 -57
  118. package/dist/telemetry/decorators.d.ts +2 -0
  119. package/dist/telemetry/decorators.d.ts.map +1 -1
  120. package/dist/telemetry/decorators.js +75 -57
  121. package/dist/telemetry/errors.cjs +2 -2
  122. package/dist/telemetry/errors.js +2 -2
  123. package/dist/telemetry/index.d.ts +1 -1
  124. package/dist/telemetry/index.d.ts.map +1 -1
  125. package/dist/telemetry/index.js +3 -1
  126. package/dist/telemetry/telemetry.cjs +62 -21
  127. package/dist/telemetry/telemetry.d.ts +14 -0
  128. package/dist/telemetry/telemetry.d.ts.map +1 -1
  129. package/dist/telemetry/telemetry.js +62 -21
  130. package/dist/telemetry/utils.cjs +9 -6
  131. package/dist/telemetry/utils.d.ts +3 -0
  132. package/dist/telemetry/utils.d.ts.map +1 -1
  133. package/dist/telemetry/utils.js +9 -6
  134. package/dist/test-utils/session-state-stores.cjs +68 -0
  135. package/dist/test-utils/session-state-stores.js +42 -0
  136. package/dist/tools/session-tool-preferences-store.cjs +86 -0
  137. package/dist/tools/session-tool-preferences-store.d.ts +29 -0
  138. package/dist/tools/session-tool-preferences-store.d.ts.map +1 -0
  139. package/dist/tools/session-tool-preferences-store.js +63 -0
  140. package/dist/tools/tool-manager.cjs +223 -68
  141. package/dist/tools/tool-manager.d.ts +29 -9
  142. package/dist/tools/tool-manager.d.ts.map +1 -1
  143. package/dist/tools/tool-manager.js +223 -68
  144. package/dist/tools/types.d.ts +7 -1
  145. package/dist/tools/types.d.ts.map +1 -1
  146. package/dist/utils/service-initializer.cjs +38 -5
  147. package/dist/utils/service-initializer.d.ts +11 -1
  148. package/dist/utils/service-initializer.d.ts.map +1 -1
  149. package/dist/utils/service-initializer.js +36 -4
  150. package/package.json +1 -1
@@ -273,11 +273,21 @@ class FileSystemResourceHandler {
273
273
  ".cache",
274
274
  ".vscode",
275
275
  ".idea",
276
- ".changeset",
277
276
  ".github",
278
277
  ".husky",
278
+ ".agents",
279
+ ".claude",
280
+ ".cursor",
281
+ ".dexto",
282
+ ".conductor",
283
+ ".logs",
279
284
  "tmp",
280
- "temp"
285
+ "temp",
286
+ "__pycache__",
287
+ ".pytest_cache",
288
+ "target",
289
+ "vendor",
290
+ "site"
281
291
  ];
282
292
  return ignoredDirectories.includes(basename);
283
293
  }
@@ -288,15 +298,24 @@ class FileSystemResourceHandler {
288
298
  if (!includeHidden) {
289
299
  const allowedDotfiles = [
290
300
  ".gitignore",
301
+ ".gitattributes",
291
302
  ".env",
292
303
  ".env.example",
304
+ ".env.local",
305
+ ".env.development",
306
+ ".env.production",
293
307
  ".npmignore",
294
308
  ".dockerignore",
295
- ".editorconfig"
309
+ ".editorconfig",
310
+ ".prettierignore",
311
+ ".eslintignore",
312
+ ".nvmrc",
313
+ ".node-version"
296
314
  ];
297
315
  if (!allowedDotfiles.includes(basename)) return false;
298
316
  }
299
317
  if (basename === ".env" || basename.startsWith(".env.")) return true;
318
+ if (basename === ".nvmrc" || basename === ".node-version") return true;
300
319
  }
301
320
  if (!ext) {
302
321
  const commonNoExtFiles = [
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var host_runtime_exports = {};
20
+ __export(host_runtime_exports, {
21
+ HostRuntimeContextSchema: () => HostRuntimeContextSchema,
22
+ HostRuntimeIdsSchema: () => HostRuntimeIdsSchema,
23
+ getHostRuntimeAttributes: () => getHostRuntimeAttributes,
24
+ getHostRuntimeBaggageEntries: () => getHostRuntimeBaggageEntries,
25
+ getHostRuntimeContextFromBaggage: () => getHostRuntimeContextFromBaggage,
26
+ isHostRuntimeBaggageKey: () => isHostRuntimeBaggageKey,
27
+ normalizeHostRuntimeContext: () => normalizeHostRuntimeContext,
28
+ resolveHostRuntimeContext: () => resolveHostRuntimeContext
29
+ });
30
+ module.exports = __toCommonJS(host_runtime_exports);
31
+ var import_api = require("@opentelemetry/api");
32
+ var import_zod = require("zod");
33
+ const HOST_RUNTIME_ENTRY_PREFIX = "hostRuntime.ids.";
34
+ const WELL_KNOWN_HOST_RUNTIME_ID_KEYS = ["runtimeId", "runId", "attemptId", "workspaceId"];
35
+ const WELL_KNOWN_HOST_RUNTIME_ID_KEY_SET = new Set(WELL_KNOWN_HOST_RUNTIME_ID_KEYS);
36
+ const HostRuntimeIdKeySchema = import_zod.z.string().min(1).regex(
37
+ /^[A-Za-z0-9._-]+$/,
38
+ "Runtime ID keys may only contain letters, numbers, dot, underscore, or hyphen."
39
+ );
40
+ const HostRuntimeIdValueSchema = import_zod.z.string().trim().min(1);
41
+ const HostRuntimeIdsSchema = import_zod.z.record(HostRuntimeIdKeySchema, HostRuntimeIdValueSchema).describe(
42
+ "Host-owned runtime IDs keyed by a stable identifier name such as runId, attemptId, or workspaceId."
43
+ );
44
+ const HostRuntimeContextSchema = import_zod.z.object({
45
+ ids: HostRuntimeIdsSchema.optional().describe(
46
+ "Optional host-owned runtime IDs used for correlation across orchestration, telemetry, logs, and events."
47
+ )
48
+ }).strict().describe("Host-owned runtime context surfaced through core runtime flows.");
49
+ function freezeHostRuntimeContext(hostRuntime) {
50
+ return Object.freeze({
51
+ ids: Object.freeze({ ...hostRuntime.ids })
52
+ });
53
+ }
54
+ function normalizeHostRuntimeContext(input) {
55
+ if (input === void 0) {
56
+ return void 0;
57
+ }
58
+ const parsed = HostRuntimeContextSchema.parse(input);
59
+ if (!parsed.ids || Object.keys(parsed.ids).length === 0) {
60
+ return void 0;
61
+ }
62
+ return freezeHostRuntimeContext({ ids: parsed.ids });
63
+ }
64
+ function resolveHostRuntimeContext({
65
+ inherited,
66
+ explicit,
67
+ runId
68
+ }) {
69
+ const ids = {
70
+ ...inherited?.ids ?? {},
71
+ ...explicit?.ids ?? {},
72
+ ...runId !== void 0 ? { runId } : {}
73
+ };
74
+ if (Object.keys(ids).length === 0) {
75
+ return void 0;
76
+ }
77
+ return normalizeHostRuntimeContext({ ids });
78
+ }
79
+ function isWellKnownHostRuntimeIdKey(key) {
80
+ return WELL_KNOWN_HOST_RUNTIME_ID_KEY_SET.has(key);
81
+ }
82
+ function isHostRuntimeBaggageKey(key) {
83
+ return key.startsWith(HOST_RUNTIME_ENTRY_PREFIX) || WELL_KNOWN_HOST_RUNTIME_ID_KEY_SET.has(key);
84
+ }
85
+ function getValidHostRuntimeIdValue(value) {
86
+ const parsed = HostRuntimeIdValueSchema.safeParse(value);
87
+ return parsed.success ? parsed.data : void 0;
88
+ }
89
+ function getHostRuntimeBaggageEntries(hostRuntime) {
90
+ const ids = hostRuntime?.ids;
91
+ if (!ids) {
92
+ return {};
93
+ }
94
+ const entries = {};
95
+ for (const [key, value] of Object.entries(ids)) {
96
+ entries[`${HOST_RUNTIME_ENTRY_PREFIX}${key}`] = { value };
97
+ if (isWellKnownHostRuntimeIdKey(key)) {
98
+ entries[key] = { value };
99
+ }
100
+ }
101
+ return entries;
102
+ }
103
+ function getHostRuntimeAttributes(hostRuntime) {
104
+ const ids = hostRuntime?.ids;
105
+ if (!ids) {
106
+ return {};
107
+ }
108
+ const attributes = {};
109
+ for (const [key, value] of Object.entries(ids)) {
110
+ attributes[`${HOST_RUNTIME_ENTRY_PREFIX}${key}`] = value;
111
+ if (isWellKnownHostRuntimeIdKey(key)) {
112
+ attributes[key] = value;
113
+ }
114
+ }
115
+ return attributes;
116
+ }
117
+ function getHostRuntimeContextFromBaggage(ctx) {
118
+ const baggage = import_api.propagation.getBaggage(ctx);
119
+ if (!baggage) {
120
+ return void 0;
121
+ }
122
+ const ids = {};
123
+ for (const [key, entry] of baggage.getAllEntries()) {
124
+ if (key.startsWith(HOST_RUNTIME_ENTRY_PREFIX)) {
125
+ const hostRuntimeKey = key.slice(HOST_RUNTIME_ENTRY_PREFIX.length);
126
+ if (!HostRuntimeIdKeySchema.safeParse(hostRuntimeKey).success) {
127
+ continue;
128
+ }
129
+ const value = getValidHostRuntimeIdValue(entry.value);
130
+ if (value === void 0) {
131
+ continue;
132
+ }
133
+ ids[hostRuntimeKey] = value;
134
+ }
135
+ }
136
+ for (const key of WELL_KNOWN_HOST_RUNTIME_ID_KEYS) {
137
+ if (ids[key] !== void 0) {
138
+ continue;
139
+ }
140
+ const entry = baggage.getEntry(key);
141
+ if (entry) {
142
+ const value = getValidHostRuntimeIdValue(entry.value);
143
+ if (value !== void 0) {
144
+ ids[key] = value;
145
+ }
146
+ }
147
+ }
148
+ if (Object.keys(ids).length === 0) {
149
+ return void 0;
150
+ }
151
+ return normalizeHostRuntimeContext({ ids });
152
+ }
153
+ // Annotate the CommonJS export names for ESM import in node:
154
+ 0 && (module.exports = {
155
+ HostRuntimeContextSchema,
156
+ HostRuntimeIdsSchema,
157
+ getHostRuntimeAttributes,
158
+ getHostRuntimeBaggageEntries,
159
+ getHostRuntimeContextFromBaggage,
160
+ isHostRuntimeBaggageKey,
161
+ normalizeHostRuntimeContext,
162
+ resolveHostRuntimeContext
163
+ });
@@ -0,0 +1,23 @@
1
+ import type { BaggageEntry, Context } from '@opentelemetry/api';
2
+ import { z } from 'zod';
3
+ export declare const HostRuntimeIdsSchema: z.ZodRecord<z.ZodString, z.ZodString>;
4
+ export declare const HostRuntimeContextSchema: z.ZodObject<{
5
+ ids: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
6
+ }, "strict", z.ZodTypeAny, {
7
+ ids?: Record<string, string> | undefined;
8
+ }, {
9
+ ids?: Record<string, string> | undefined;
10
+ }>;
11
+ export type HostRuntimeIds = z.output<typeof HostRuntimeIdsSchema>;
12
+ export type HostRuntimeContext = z.output<typeof HostRuntimeContextSchema>;
13
+ export declare function normalizeHostRuntimeContext(input: z.input<typeof HostRuntimeContextSchema> | undefined): HostRuntimeContext | undefined;
14
+ export declare function resolveHostRuntimeContext({ inherited, explicit, runId, }: {
15
+ inherited?: HostRuntimeContext | undefined;
16
+ explicit?: HostRuntimeContext | undefined;
17
+ runId?: string | undefined;
18
+ }): HostRuntimeContext | undefined;
19
+ export declare function isHostRuntimeBaggageKey(key: string): boolean;
20
+ export declare function getHostRuntimeBaggageEntries(hostRuntime?: HostRuntimeContext): Record<string, BaggageEntry>;
21
+ export declare function getHostRuntimeAttributes(hostRuntime?: HostRuntimeContext): Record<string, string>;
22
+ export declare function getHostRuntimeContextFromBaggage(ctx: Context): HostRuntimeContext | undefined;
23
+ //# sourceMappingURL=host-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/host-runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB,eAAO,MAAM,oBAAoB,uCAI5B,CAAC;AAEN,eAAO,MAAM,wBAAwB;;;;;;EAO2C,CAAC;AAEjF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACnE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAQ3E,wBAAgB,2BAA2B,CACvC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,GAAG,SAAS,GAC5D,kBAAkB,GAAG,SAAS,CAWhC;AAED,wBAAgB,yBAAyB,CAAC,EACtC,SAAS,EACT,QAAQ,EACR,KAAK,GACR,EAAE;IACC,SAAS,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAC1C,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B,GAAG,kBAAkB,GAAG,SAAS,CAYjC;AAQD,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5D;AAOD,wBAAgB,4BAA4B,CACxC,WAAW,CAAC,EAAE,kBAAkB,GACjC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAe9B;AAED,wBAAgB,wBAAwB,CAAC,WAAW,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAejG;AAED,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,GAAG,SAAS,CA0C7F"}
@@ -0,0 +1,133 @@
1
+ import "../chunk-PTJYTZNU.js";
2
+ import { propagation } from "@opentelemetry/api";
3
+ import { z } from "zod";
4
+ const HOST_RUNTIME_ENTRY_PREFIX = "hostRuntime.ids.";
5
+ const WELL_KNOWN_HOST_RUNTIME_ID_KEYS = ["runtimeId", "runId", "attemptId", "workspaceId"];
6
+ const WELL_KNOWN_HOST_RUNTIME_ID_KEY_SET = new Set(WELL_KNOWN_HOST_RUNTIME_ID_KEYS);
7
+ const HostRuntimeIdKeySchema = z.string().min(1).regex(
8
+ /^[A-Za-z0-9._-]+$/,
9
+ "Runtime ID keys may only contain letters, numbers, dot, underscore, or hyphen."
10
+ );
11
+ const HostRuntimeIdValueSchema = z.string().trim().min(1);
12
+ const HostRuntimeIdsSchema = z.record(HostRuntimeIdKeySchema, HostRuntimeIdValueSchema).describe(
13
+ "Host-owned runtime IDs keyed by a stable identifier name such as runId, attemptId, or workspaceId."
14
+ );
15
+ const HostRuntimeContextSchema = z.object({
16
+ ids: HostRuntimeIdsSchema.optional().describe(
17
+ "Optional host-owned runtime IDs used for correlation across orchestration, telemetry, logs, and events."
18
+ )
19
+ }).strict().describe("Host-owned runtime context surfaced through core runtime flows.");
20
+ function freezeHostRuntimeContext(hostRuntime) {
21
+ return Object.freeze({
22
+ ids: Object.freeze({ ...hostRuntime.ids })
23
+ });
24
+ }
25
+ function normalizeHostRuntimeContext(input) {
26
+ if (input === void 0) {
27
+ return void 0;
28
+ }
29
+ const parsed = HostRuntimeContextSchema.parse(input);
30
+ if (!parsed.ids || Object.keys(parsed.ids).length === 0) {
31
+ return void 0;
32
+ }
33
+ return freezeHostRuntimeContext({ ids: parsed.ids });
34
+ }
35
+ function resolveHostRuntimeContext({
36
+ inherited,
37
+ explicit,
38
+ runId
39
+ }) {
40
+ const ids = {
41
+ ...inherited?.ids ?? {},
42
+ ...explicit?.ids ?? {},
43
+ ...runId !== void 0 ? { runId } : {}
44
+ };
45
+ if (Object.keys(ids).length === 0) {
46
+ return void 0;
47
+ }
48
+ return normalizeHostRuntimeContext({ ids });
49
+ }
50
+ function isWellKnownHostRuntimeIdKey(key) {
51
+ return WELL_KNOWN_HOST_RUNTIME_ID_KEY_SET.has(key);
52
+ }
53
+ function isHostRuntimeBaggageKey(key) {
54
+ return key.startsWith(HOST_RUNTIME_ENTRY_PREFIX) || WELL_KNOWN_HOST_RUNTIME_ID_KEY_SET.has(key);
55
+ }
56
+ function getValidHostRuntimeIdValue(value) {
57
+ const parsed = HostRuntimeIdValueSchema.safeParse(value);
58
+ return parsed.success ? parsed.data : void 0;
59
+ }
60
+ function getHostRuntimeBaggageEntries(hostRuntime) {
61
+ const ids = hostRuntime?.ids;
62
+ if (!ids) {
63
+ return {};
64
+ }
65
+ const entries = {};
66
+ for (const [key, value] of Object.entries(ids)) {
67
+ entries[`${HOST_RUNTIME_ENTRY_PREFIX}${key}`] = { value };
68
+ if (isWellKnownHostRuntimeIdKey(key)) {
69
+ entries[key] = { value };
70
+ }
71
+ }
72
+ return entries;
73
+ }
74
+ function getHostRuntimeAttributes(hostRuntime) {
75
+ const ids = hostRuntime?.ids;
76
+ if (!ids) {
77
+ return {};
78
+ }
79
+ const attributes = {};
80
+ for (const [key, value] of Object.entries(ids)) {
81
+ attributes[`${HOST_RUNTIME_ENTRY_PREFIX}${key}`] = value;
82
+ if (isWellKnownHostRuntimeIdKey(key)) {
83
+ attributes[key] = value;
84
+ }
85
+ }
86
+ return attributes;
87
+ }
88
+ function getHostRuntimeContextFromBaggage(ctx) {
89
+ const baggage = propagation.getBaggage(ctx);
90
+ if (!baggage) {
91
+ return void 0;
92
+ }
93
+ const ids = {};
94
+ for (const [key, entry] of baggage.getAllEntries()) {
95
+ if (key.startsWith(HOST_RUNTIME_ENTRY_PREFIX)) {
96
+ const hostRuntimeKey = key.slice(HOST_RUNTIME_ENTRY_PREFIX.length);
97
+ if (!HostRuntimeIdKeySchema.safeParse(hostRuntimeKey).success) {
98
+ continue;
99
+ }
100
+ const value = getValidHostRuntimeIdValue(entry.value);
101
+ if (value === void 0) {
102
+ continue;
103
+ }
104
+ ids[hostRuntimeKey] = value;
105
+ }
106
+ }
107
+ for (const key of WELL_KNOWN_HOST_RUNTIME_ID_KEYS) {
108
+ if (ids[key] !== void 0) {
109
+ continue;
110
+ }
111
+ const entry = baggage.getEntry(key);
112
+ if (entry) {
113
+ const value = getValidHostRuntimeIdValue(entry.value);
114
+ if (value !== void 0) {
115
+ ids[key] = value;
116
+ }
117
+ }
118
+ }
119
+ if (Object.keys(ids).length === 0) {
120
+ return void 0;
121
+ }
122
+ return normalizeHostRuntimeContext({ ids });
123
+ }
124
+ export {
125
+ HostRuntimeContextSchema,
126
+ HostRuntimeIdsSchema,
127
+ getHostRuntimeAttributes,
128
+ getHostRuntimeBaggageEntries,
129
+ getHostRuntimeContextFromBaggage,
130
+ isHostRuntimeBaggageKey,
131
+ normalizeHostRuntimeContext,
132
+ resolveHostRuntimeContext
133
+ };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var runtime_exports = {};
20
+ __export(runtime_exports, {
21
+ HostRuntimeContextSchema: () => import_host_runtime.HostRuntimeContextSchema,
22
+ HostRuntimeIdsSchema: () => import_host_runtime.HostRuntimeIdsSchema,
23
+ buildHostRuntimeBaggageEntries: () => import_host_runtime.getHostRuntimeBaggageEntries,
24
+ getHostRuntimeAttributes: () => import_host_runtime.getHostRuntimeAttributes,
25
+ getHostRuntimeBaggageEntries: () => import_host_runtime.getHostRuntimeBaggageEntries,
26
+ getHostRuntimeContextFromBaggage: () => import_host_runtime.getHostRuntimeContextFromBaggage,
27
+ normalizeHostRuntimeContext: () => import_host_runtime.normalizeHostRuntimeContext,
28
+ resolveHostRuntimeContext: () => import_host_runtime.resolveHostRuntimeContext
29
+ });
30
+ module.exports = __toCommonJS(runtime_exports);
31
+ var import_host_runtime = require("./host-runtime.js");
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ HostRuntimeContextSchema,
35
+ HostRuntimeIdsSchema,
36
+ buildHostRuntimeBaggageEntries,
37
+ getHostRuntimeAttributes,
38
+ getHostRuntimeBaggageEntries,
39
+ getHostRuntimeContextFromBaggage,
40
+ normalizeHostRuntimeContext,
41
+ resolveHostRuntimeContext
42
+ });
@@ -0,0 +1,2 @@
1
+ export { HostRuntimeContextSchema, HostRuntimeIdsSchema, getHostRuntimeBaggageEntries as buildHostRuntimeBaggageEntries, getHostRuntimeAttributes, getHostRuntimeBaggageEntries, getHostRuntimeContextFromBaggage, normalizeHostRuntimeContext, resolveHostRuntimeContext, type HostRuntimeContext, type HostRuntimeIds, } from './host-runtime.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,wBAAwB,EACxB,oBAAoB,EACpB,4BAA4B,IAAI,8BAA8B,EAC9D,wBAAwB,EACxB,4BAA4B,EAC5B,gCAAgC,EAChC,2BAA2B,EAC3B,yBAAyB,EACzB,KAAK,kBAAkB,EACvB,KAAK,cAAc,GACtB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import "../chunk-PTJYTZNU.js";
2
+ import {
3
+ HostRuntimeContextSchema,
4
+ HostRuntimeIdsSchema,
5
+ getHostRuntimeBaggageEntries,
6
+ getHostRuntimeAttributes,
7
+ getHostRuntimeBaggageEntries as getHostRuntimeBaggageEntries2,
8
+ getHostRuntimeContextFromBaggage,
9
+ normalizeHostRuntimeContext,
10
+ resolveHostRuntimeContext
11
+ } from "./host-runtime.js";
12
+ export {
13
+ HostRuntimeContextSchema,
14
+ HostRuntimeIdsSchema,
15
+ getHostRuntimeBaggageEntries as buildHostRuntimeBaggageEntries,
16
+ getHostRuntimeAttributes,
17
+ getHostRuntimeBaggageEntries2 as getHostRuntimeBaggageEntries,
18
+ getHostRuntimeContextFromBaggage,
19
+ normalizeHostRuntimeContext,
20
+ resolveHostRuntimeContext
21
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var run_context_exports = {};
20
+ __export(run_context_exports, {
21
+ createAgentRunContext: () => createAgentRunContext
22
+ });
23
+ module.exports = __toCommonJS(run_context_exports);
24
+ var import_api = require("@opentelemetry/api");
25
+ var import_host_runtime = require("./host-runtime.js");
26
+ function createAgentRunContext(options) {
27
+ const hostRuntime = (0, import_host_runtime.normalizeHostRuntimeContext)(options.hostRuntime);
28
+ const parentContext = options.parentContext ?? import_api.context.active();
29
+ const existingBaggage = import_api.propagation.getBaggage(parentContext);
30
+ const baggageEntries = {};
31
+ if (existingBaggage) {
32
+ existingBaggage.getAllEntries().forEach(([key, entry]) => {
33
+ if ((0, import_host_runtime.isHostRuntimeBaggageKey)(key)) {
34
+ return;
35
+ }
36
+ baggageEntries[key] = { ...entry };
37
+ });
38
+ }
39
+ Object.assign(baggageEntries, (0, import_host_runtime.getHostRuntimeBaggageEntries)(hostRuntime));
40
+ baggageEntries.sessionId = { ...baggageEntries.sessionId, value: options.sessionId };
41
+ return Object.freeze({
42
+ sessionId: options.sessionId,
43
+ ...hostRuntime !== void 0 ? { hostRuntime } : {},
44
+ telemetryContext: import_api.propagation.setBaggage(
45
+ parentContext,
46
+ import_api.propagation.createBaggage(baggageEntries)
47
+ )
48
+ });
49
+ }
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ createAgentRunContext
53
+ });
@@ -0,0 +1,13 @@
1
+ import { type Context } from '@opentelemetry/api';
2
+ import { type HostRuntimeContext } from './host-runtime.js';
3
+ export interface AgentRunContext {
4
+ sessionId: string;
5
+ hostRuntime?: HostRuntimeContext | undefined;
6
+ telemetryContext: Context;
7
+ }
8
+ export declare function createAgentRunContext(options: {
9
+ sessionId: string;
10
+ hostRuntime?: HostRuntimeContext | undefined;
11
+ parentContext?: Context | undefined;
12
+ }): AgentRunContext;
13
+ //# sourceMappingURL=run-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-context.d.ts","sourceRoot":"","sources":["../../src/runtime/run-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAIH,KAAK,kBAAkB,EAC1B,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,eAAe;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAC7C,gBAAgB,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAC7C,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACvC,GAAG,eAAe,CA0BlB"}
@@ -0,0 +1,34 @@
1
+ import "../chunk-PTJYTZNU.js";
2
+ import { context, propagation } from "@opentelemetry/api";
3
+ import {
4
+ getHostRuntimeBaggageEntries,
5
+ isHostRuntimeBaggageKey,
6
+ normalizeHostRuntimeContext
7
+ } from "./host-runtime.js";
8
+ function createAgentRunContext(options) {
9
+ const hostRuntime = normalizeHostRuntimeContext(options.hostRuntime);
10
+ const parentContext = options.parentContext ?? context.active();
11
+ const existingBaggage = propagation.getBaggage(parentContext);
12
+ const baggageEntries = {};
13
+ if (existingBaggage) {
14
+ existingBaggage.getAllEntries().forEach(([key, entry]) => {
15
+ if (isHostRuntimeBaggageKey(key)) {
16
+ return;
17
+ }
18
+ baggageEntries[key] = { ...entry };
19
+ });
20
+ }
21
+ Object.assign(baggageEntries, getHostRuntimeBaggageEntries(hostRuntime));
22
+ baggageEntries.sessionId = { ...baggageEntries.sessionId, value: options.sessionId };
23
+ return Object.freeze({
24
+ sessionId: options.sessionId,
25
+ ...hostRuntime !== void 0 ? { hostRuntime } : {},
26
+ telemetryContext: propagation.setBaggage(
27
+ parentContext,
28
+ propagation.createBaggage(baggageEntries)
29
+ )
30
+ });
31
+ }
32
+ export {
33
+ createAgentRunContext
34
+ };