@agentuity/runtime 0.0.69 → 0.0.70
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/AGENTS.md +88 -10
- package/README.md +0 -2
- package/dist/_config.d.ts +16 -0
- package/dist/_config.d.ts.map +1 -1
- package/dist/_config.js +16 -0
- package/dist/_config.js.map +1 -1
- package/dist/_context.d.ts +17 -15
- package/dist/_context.d.ts.map +1 -1
- package/dist/_context.js +17 -8
- package/dist/_context.js.map +1 -1
- package/dist/_server.d.ts.map +1 -1
- package/dist/_server.js +23 -14
- package/dist/_server.js.map +1 -1
- package/dist/_services.d.ts.map +1 -1
- package/dist/_services.js +2 -29
- package/dist/_services.js.map +1 -1
- package/dist/_validation.d.ts +3 -3
- package/dist/_validation.d.ts.map +1 -1
- package/dist/_validation.js.map +1 -1
- package/dist/agent.d.ts +289 -107
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +206 -149
- package/dist/agent.js.map +1 -1
- package/dist/app.d.ts +6 -18
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +1 -1
- package/dist/app.js.map +1 -1
- package/dist/eval.d.ts +4 -4
- package/dist/eval.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/otel/config.d.ts.map +1 -1
- package/dist/otel/config.js +5 -2
- package/dist/otel/config.js.map +1 -1
- package/dist/otel/console.d.ts +10 -6
- package/dist/otel/console.d.ts.map +1 -1
- package/dist/otel/console.js +31 -13
- package/dist/otel/console.js.map +1 -1
- package/dist/otel/logger.d.ts.map +1 -1
- package/dist/otel/logger.js +0 -19
- package/dist/otel/logger.js.map +1 -1
- package/dist/otel/otel.d.ts +2 -1
- package/dist/otel/otel.d.ts.map +1 -1
- package/dist/otel/otel.js +28 -15
- package/dist/otel/otel.js.map +1 -1
- package/dist/services/local/_db.d.ts.map +1 -1
- package/dist/services/local/_db.js +1 -22
- package/dist/services/local/_db.js.map +1 -1
- package/dist/services/local/_router.d.ts.map +1 -1
- package/dist/services/local/_router.js +0 -32
- package/dist/services/local/_router.js.map +1 -1
- package/dist/services/local/index.d.ts +0 -1
- package/dist/services/local/index.d.ts.map +1 -1
- package/dist/services/local/index.js +0 -1
- package/dist/services/local/index.js.map +1 -1
- package/dist/session.d.ts +2 -2
- package/dist/validator.d.ts +140 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +146 -0
- package/dist/validator.js.map +1 -0
- package/dist/workbench.d.ts.map +1 -1
- package/dist/workbench.js +38 -29
- package/dist/workbench.js.map +1 -1
- package/package.json +6 -6
- package/src/_config.ts +19 -0
- package/src/_context.ts +25 -31
- package/src/_server.ts +26 -14
- package/src/_services.ts +0 -28
- package/src/_validation.ts +3 -7
- package/src/agent.ts +555 -348
- package/src/app.ts +5 -18
- package/src/eval.ts +6 -6
- package/src/index.ts +2 -1
- package/src/otel/config.ts +5 -2
- package/src/otel/console.ts +34 -20
- package/src/otel/logger.ts +0 -18
- package/src/otel/otel.ts +43 -29
- package/src/services/local/_db.ts +1 -27
- package/src/services/local/_router.ts +0 -46
- package/src/services/local/index.ts +0 -1
- package/src/session.ts +2 -2
- package/src/validator.ts +277 -0
- package/src/workbench.ts +38 -32
- package/dist/agent.validator.test.d.ts +0 -2
- package/dist/agent.validator.test.d.ts.map +0 -1
- package/dist/agent.validator.test.js +0 -508
- package/dist/agent.validator.test.js.map +0 -1
- package/dist/services/local/objectstore.d.ts +0 -19
- package/dist/services/local/objectstore.d.ts.map +0 -1
- package/dist/services/local/objectstore.js +0 -117
- package/dist/services/local/objectstore.js.map +0 -1
- package/src/agent.validator.test.ts +0 -587
- package/src/services/local/objectstore.ts +0 -177
package/src/app.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { createServer, getLogger } from './_server';
|
|
|
8
8
|
import type { Meter, Tracer } from '@opentelemetry/api';
|
|
9
9
|
import type {
|
|
10
10
|
KeyValueStorage,
|
|
11
|
-
ObjectStorage,
|
|
12
11
|
SessionEventProvider,
|
|
13
12
|
EvalRunEventProvider,
|
|
14
13
|
StreamStorage,
|
|
@@ -16,7 +15,7 @@ import type {
|
|
|
16
15
|
SessionStartEvent,
|
|
17
16
|
} from '@agentuity/core';
|
|
18
17
|
import type { Email } from './io/email';
|
|
19
|
-
import type { Agent, AgentContext
|
|
18
|
+
import type { Agent, AgentContext } from './agent';
|
|
20
19
|
import type { ThreadProvider, SessionProvider, Session, Thread } from './session';
|
|
21
20
|
import type WaitUntilHandler from './_waituntil';
|
|
22
21
|
|
|
@@ -44,10 +43,6 @@ export interface AppConfig<TAppState = Record<string, never>> {
|
|
|
44
43
|
* the KeyValueStorage to override instead of the default
|
|
45
44
|
*/
|
|
46
45
|
keyvalue?: KeyValueStorage;
|
|
47
|
-
/**
|
|
48
|
-
* the ObjectStorage to override instead of the default
|
|
49
|
-
*/
|
|
50
|
-
object?: ObjectStorage;
|
|
51
46
|
/**
|
|
52
47
|
* the StreamStorage to override instead of the default
|
|
53
48
|
*/
|
|
@@ -97,9 +92,7 @@ export interface Variables<TAppState = Record<string, never>> {
|
|
|
97
92
|
sessionId: string;
|
|
98
93
|
thread: Thread;
|
|
99
94
|
session: Session;
|
|
100
|
-
agent: AgentRegistry;
|
|
101
95
|
kv: KeyValueStorage;
|
|
102
|
-
objectstore: ObjectStorage;
|
|
103
96
|
stream: StreamStorage;
|
|
104
97
|
vector: VectorStorage;
|
|
105
98
|
app: TAppState;
|
|
@@ -119,17 +112,11 @@ export interface Env<TAppState = Record<string, never>> extends HonoEnv {
|
|
|
119
112
|
}
|
|
120
113
|
|
|
121
114
|
type AppEventMap<TAppState = Record<string, never>> = {
|
|
122
|
-
'agent.started': [
|
|
123
|
-
|
|
124
|
-
AgentContext<any, any, any, any, TAppState>,
|
|
125
|
-
];
|
|
126
|
-
'agent.completed': [
|
|
127
|
-
Agent<any, any, any, any, TAppState>,
|
|
128
|
-
AgentContext<any, any, any, any, TAppState>,
|
|
129
|
-
];
|
|
115
|
+
'agent.started': [Agent<any, any, any, any, TAppState>, AgentContext<any, any, TAppState>];
|
|
116
|
+
'agent.completed': [Agent<any, any, any, any, TAppState>, AgentContext<any, any, TAppState>];
|
|
130
117
|
'agent.errored': [
|
|
131
118
|
Agent<any, any, any, any, TAppState>,
|
|
132
|
-
AgentContext<any, any,
|
|
119
|
+
AgentContext<any, any, TAppState>,
|
|
133
120
|
Error,
|
|
134
121
|
];
|
|
135
122
|
'session.started': [Session];
|
|
@@ -356,7 +343,7 @@ export function getApp(): App<any> | null {
|
|
|
356
343
|
* });
|
|
357
344
|
*
|
|
358
345
|
* // Access state in agents
|
|
359
|
-
* const agent = createAgent({
|
|
346
|
+
* const agent = createAgent('user-query', {
|
|
360
347
|
* handler: async (ctx, input) => {
|
|
361
348
|
* const db = ctx.app.db; // Strongly typed!
|
|
362
349
|
* return db.query('SELECT * FROM users');
|
package/src/eval.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import type { StandardSchemaV1 } from '@agentuity/core';
|
|
2
|
+
import type { StandardSchemaV1, InferInput, InferOutput } from '@agentuity/core';
|
|
3
3
|
import type { AgentContext } from './agent';
|
|
4
4
|
|
|
5
5
|
// Eval SDK types
|
|
@@ -75,14 +75,14 @@ export type ExternalEvalMetadata = {
|
|
|
75
75
|
|
|
76
76
|
export type EvalMetadata = InternalEvalMetadata & ExternalEvalMetadata;
|
|
77
77
|
|
|
78
|
-
type InferSchemaInput<T> = T extends StandardSchemaV1 ?
|
|
79
|
-
type InferSchemaOutput<T> = T extends StandardSchemaV1 ?
|
|
78
|
+
type InferSchemaInput<T> = T extends StandardSchemaV1 ? InferInput<T> : any;
|
|
79
|
+
type InferSchemaOutput<T> = T extends StandardSchemaV1 ? InferOutput<T> : any;
|
|
80
80
|
|
|
81
|
-
export type EvalFunction<TInput = any, TOutput = any> = TInput extends undefined
|
|
82
|
-
? TOutput extends undefined
|
|
81
|
+
export type EvalFunction<TInput = any, TOutput = any> = [TInput] extends [undefined]
|
|
82
|
+
? [TOutput] extends [undefined]
|
|
83
83
|
? (ctx: EvalContext) => Promise<EvalRunResult>
|
|
84
84
|
: (ctx: EvalContext, output: TOutput) => Promise<EvalRunResult>
|
|
85
|
-
: TOutput extends undefined
|
|
85
|
+
: [TOutput] extends [undefined]
|
|
86
86
|
? (ctx: EvalContext, input: TInput) => Promise<EvalRunResult>
|
|
87
87
|
: (ctx: EvalContext, input: TInput, output: TOutput) => Promise<EvalRunResult>;
|
|
88
88
|
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './router';
|
|
|
5
5
|
export * from './eval';
|
|
6
6
|
export * from './session';
|
|
7
7
|
export * from './workbench';
|
|
8
|
+
export * from './validator';
|
|
8
9
|
export type { Logger } from './logger';
|
|
9
10
|
export { getRouter, getAppState } from './_server';
|
|
10
11
|
export { Email, parseEmail } from './io/email';
|
|
@@ -36,7 +37,7 @@ export type { RouteSchema, GetRouteSchema } from './_validation';
|
|
|
36
37
|
* });
|
|
37
38
|
*
|
|
38
39
|
* // In your agent:
|
|
39
|
-
* const agent = createAgent({
|
|
40
|
+
* const agent = createAgent('user-query', {
|
|
40
41
|
* handler: async (ctx, input) => {
|
|
41
42
|
* // ctx.app is strongly typed with { db, redis }!
|
|
42
43
|
* const user = await ctx.app.db.query('SELECT * FROM users');
|
package/src/otel/config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { LogLevel } from '@agentuity/core';
|
|
2
2
|
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
3
|
+
import { getServiceUrls } from '@agentuity/server';
|
|
3
4
|
import * as runtimeConfig from '../_config';
|
|
4
5
|
import type { OtelConfig, OtelResponse } from './otel';
|
|
5
6
|
import { registerOtel } from './otel';
|
|
@@ -22,8 +23,10 @@ interface OtelRegisterConfig {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export function register(registerConfig: OtelRegisterConfig): OtelResponse {
|
|
25
|
-
const
|
|
26
|
-
const
|
|
26
|
+
const region = process.env.AGENTUITY_REGION ?? 'usc';
|
|
27
|
+
const serviceUrls = getServiceUrls(region);
|
|
28
|
+
const url = serviceUrls.otel;
|
|
29
|
+
const bearerToken = process.env.AGENTUITY_OTLP_BEARER_TOKEN ?? process.env.AGENTUITY_SDK_KEY;
|
|
27
30
|
const config: OtelConfig = {
|
|
28
31
|
spanProcessors: registerConfig.processors,
|
|
29
32
|
name: runtimeConfig.getAppName(),
|
package/src/otel/console.ts
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
import { SeverityNumber } from '@opentelemetry/api-logs';
|
|
2
2
|
import { type ExportResult, ExportResultCode } from '@opentelemetry/core';
|
|
3
3
|
import type { LogRecordExporter, ReadableLogRecord } from '@opentelemetry/sdk-logs';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import type { SpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base';
|
|
5
|
+
import { __originalConsole } from './logger';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Console implementation of the LogRecordExporter interface
|
|
9
|
+
* Uses __originalConsole to avoid infinite loop when console is patched
|
|
9
10
|
*/
|
|
10
11
|
export class ConsoleLogRecordExporter implements LogRecordExporter {
|
|
11
|
-
private readonly logger: Logger;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new console log record exporter
|
|
15
|
-
*/
|
|
16
|
-
constructor(logLevel: LogLevel) {
|
|
17
|
-
this.logger = createLogger(
|
|
18
|
-
logLevel,
|
|
19
|
-
false,
|
|
20
|
-
(process.env.COLOR_SCHEME as ColorScheme) ?? 'dark'
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
12
|
/**
|
|
25
13
|
* Exports log records to the console
|
|
26
14
|
*
|
|
@@ -29,21 +17,23 @@ export class ConsoleLogRecordExporter implements LogRecordExporter {
|
|
|
29
17
|
*/
|
|
30
18
|
export(logs: ReadableLogRecord[], resultCallback: (result: ExportResult) => void): void {
|
|
31
19
|
for (const log of logs) {
|
|
20
|
+
const severity = log.severityNumber ? SeverityNumber[log.severityNumber] : 'INFO';
|
|
21
|
+
const msg = `[${severity}] ${log.body}`;
|
|
32
22
|
switch (log.severityNumber) {
|
|
33
23
|
case SeverityNumber.DEBUG:
|
|
34
|
-
|
|
24
|
+
__originalConsole.debug(msg);
|
|
35
25
|
break;
|
|
36
26
|
case SeverityNumber.INFO:
|
|
37
|
-
|
|
27
|
+
__originalConsole.info(msg);
|
|
38
28
|
break;
|
|
39
29
|
case SeverityNumber.WARN:
|
|
40
|
-
|
|
30
|
+
__originalConsole.warn(msg);
|
|
41
31
|
break;
|
|
42
32
|
case SeverityNumber.ERROR:
|
|
43
|
-
|
|
33
|
+
__originalConsole.error(msg);
|
|
44
34
|
break;
|
|
45
35
|
default:
|
|
46
|
-
|
|
36
|
+
__originalConsole.log(msg);
|
|
47
37
|
break;
|
|
48
38
|
}
|
|
49
39
|
}
|
|
@@ -59,3 +49,27 @@ export class ConsoleLogRecordExporter implements LogRecordExporter {
|
|
|
59
49
|
return Promise.resolve();
|
|
60
50
|
}
|
|
61
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Console implementation of the SpanExporter interface
|
|
55
|
+
* Uses __originalConsole to avoid infinite loop when console is patched
|
|
56
|
+
*/
|
|
57
|
+
export class DebugSpanExporter implements SpanExporter {
|
|
58
|
+
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {
|
|
59
|
+
for (const span of spans) {
|
|
60
|
+
__originalConsole.log('[SPAN]', {
|
|
61
|
+
name: span.name,
|
|
62
|
+
traceId: span.spanContext().traceId,
|
|
63
|
+
spanId: span.spanContext().spanId,
|
|
64
|
+
duration: span.duration,
|
|
65
|
+
status: span.status,
|
|
66
|
+
attributes: span.attributes,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
shutdown(): Promise<void> {
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/otel/logger.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { safeStringify, type LogLevel } from '@agentuity/core';
|
|
|
3
3
|
import * as LogsAPI from '@opentelemetry/api-logs';
|
|
4
4
|
import type { Logger } from '../logger';
|
|
5
5
|
import ConsoleLogger from '../logger/console';
|
|
6
|
-
import { getAgentContext } from '../_context';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Reference to the original console object before patching
|
|
@@ -41,23 +40,6 @@ export class OtelLogger implements Logger {
|
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
private getAttributes(): Record<string, unknown> | undefined {
|
|
44
|
-
try {
|
|
45
|
-
const actx = getAgentContext();
|
|
46
|
-
const current = actx.current?.metadata;
|
|
47
|
-
if (current) {
|
|
48
|
-
const result: Record<string, unknown> = {
|
|
49
|
-
...(this.context ?? {}),
|
|
50
|
-
};
|
|
51
|
-
for (const [key, value] of Object.entries(current)) {
|
|
52
|
-
if (value !== null && value !== undefined) {
|
|
53
|
-
result[`@agentuity/${key}`] = value as unknown;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
} catch {
|
|
59
|
-
/* fall through */
|
|
60
|
-
}
|
|
61
43
|
return this.context;
|
|
62
44
|
}
|
|
63
45
|
|
package/src/otel/otel.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
2
|
-
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
2
|
+
import { BatchSpanProcessor, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
3
3
|
import opentelemetry, { type Meter, metrics, propagation, type Tracer } from '@opentelemetry/api';
|
|
4
4
|
import * as LogsAPI from '@opentelemetry/api-logs';
|
|
5
5
|
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
@@ -26,7 +26,7 @@ import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
|
26
26
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
|
|
27
27
|
import { initialize } from '@traceloop/node-server-sdk';
|
|
28
28
|
import type { Logger } from '../logger';
|
|
29
|
-
import { ConsoleLogRecordExporter } from './console';
|
|
29
|
+
import { ConsoleLogRecordExporter, DebugSpanExporter } from './console';
|
|
30
30
|
import { instrumentFetch } from './fetch';
|
|
31
31
|
import { createLogger, patchConsole } from './logger';
|
|
32
32
|
import { getSDKVersion, isAuthenticated } from '../_config';
|
|
@@ -88,19 +88,22 @@ export const createAgentuityLoggerProvider = ({
|
|
|
88
88
|
url,
|
|
89
89
|
headers,
|
|
90
90
|
resource,
|
|
91
|
-
logLevel,
|
|
92
91
|
jsonlBasePath,
|
|
92
|
+
useConsoleExporters,
|
|
93
93
|
}: {
|
|
94
94
|
url?: string;
|
|
95
95
|
headers?: Record<string, string>;
|
|
96
96
|
resource: Resource;
|
|
97
97
|
logLevel: LogLevel;
|
|
98
98
|
jsonlBasePath?: string;
|
|
99
|
+
useConsoleExporters: boolean;
|
|
99
100
|
}) => {
|
|
100
101
|
let processor: LogRecordProcessor;
|
|
101
102
|
let exporter: OTLPLogExporter | JSONLLogExporter | undefined;
|
|
102
103
|
|
|
103
|
-
if (
|
|
104
|
+
if (useConsoleExporters) {
|
|
105
|
+
processor = new SimpleLogRecordProcessor(new ConsoleLogRecordExporter());
|
|
106
|
+
} else if (jsonlBasePath) {
|
|
104
107
|
exporter = new JSONLLogExporter(jsonlBasePath);
|
|
105
108
|
processor = new BatchLogRecordProcessor(exporter);
|
|
106
109
|
} else if (url) {
|
|
@@ -114,7 +117,7 @@ export const createAgentuityLoggerProvider = ({
|
|
|
114
117
|
exporter = otlpExporter;
|
|
115
118
|
processor = new BatchLogRecordProcessor(otlpExporter);
|
|
116
119
|
} else {
|
|
117
|
-
processor = new SimpleLogRecordProcessor(new ConsoleLogRecordExporter(
|
|
120
|
+
processor = new SimpleLogRecordProcessor(new ConsoleLogRecordExporter());
|
|
118
121
|
}
|
|
119
122
|
const provider = new LoggerProvider({
|
|
120
123
|
resource,
|
|
@@ -184,6 +187,9 @@ export function registerOtel(config: OtelConfig): OtelResponse {
|
|
|
184
187
|
headers.Authorization = `Bearer ${bearerToken}`;
|
|
185
188
|
}
|
|
186
189
|
|
|
190
|
+
// use console debug exporters for local debugging
|
|
191
|
+
const useConsoleExporters = process.env.AGENTUITY_DEBUG_OTEL_CONSOLE === 'true';
|
|
192
|
+
|
|
187
193
|
const resource = createResource(config);
|
|
188
194
|
const loggerProvider = createAgentuityLoggerProvider({
|
|
189
195
|
url,
|
|
@@ -191,6 +197,7 @@ export function registerOtel(config: OtelConfig): OtelResponse {
|
|
|
191
197
|
resource,
|
|
192
198
|
logLevel,
|
|
193
199
|
jsonlBasePath,
|
|
200
|
+
useConsoleExporters,
|
|
194
201
|
});
|
|
195
202
|
const attrs = {
|
|
196
203
|
'@agentuity/orgId': orgId ?? 'unknown',
|
|
@@ -205,6 +212,7 @@ export function registerOtel(config: OtelConfig): OtelResponse {
|
|
|
205
212
|
// must do this after we have created the logger
|
|
206
213
|
patchConsole(!!url, attrs, logLevel);
|
|
207
214
|
|
|
215
|
+
// Build trace exporter (OTLP or JSONL)
|
|
208
216
|
const traceExporter = jsonlBasePath
|
|
209
217
|
? new JSONLTraceExporter(jsonlBasePath)
|
|
210
218
|
: url
|
|
@@ -216,6 +224,7 @@ export function registerOtel(config: OtelConfig): OtelResponse {
|
|
|
216
224
|
})
|
|
217
225
|
: undefined;
|
|
218
226
|
|
|
227
|
+
// Build metric exporter (OTLP or JSONL)
|
|
219
228
|
const metricExporter = jsonlBasePath
|
|
220
229
|
? new JSONLMetricExporter(jsonlBasePath)
|
|
221
230
|
: url
|
|
@@ -227,28 +236,36 @@ export function registerOtel(config: OtelConfig): OtelResponse {
|
|
|
227
236
|
})
|
|
228
237
|
: undefined;
|
|
229
238
|
|
|
230
|
-
// Create span
|
|
231
|
-
const
|
|
239
|
+
// Create span processors
|
|
240
|
+
const spanProcessors: SpanProcessor[] = [];
|
|
241
|
+
|
|
242
|
+
// Add OTLP/JSONL span processor if we have an exporter
|
|
243
|
+
if (traceExporter) {
|
|
244
|
+
spanProcessors.push(new BatchSpanProcessor(traceExporter));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Add debug span processor if console debugging is enabled
|
|
248
|
+
if (useConsoleExporters) {
|
|
249
|
+
spanProcessors.push(new SimpleSpanProcessor(new DebugSpanExporter()));
|
|
250
|
+
}
|
|
232
251
|
|
|
233
252
|
// Create a separate metric reader for the NodeSDK
|
|
234
|
-
const sdkMetricReader =
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
: undefined;
|
|
253
|
+
const sdkMetricReader = metricExporter
|
|
254
|
+
? new PeriodicExportingMetricReader({
|
|
255
|
+
exporter: metricExporter,
|
|
256
|
+
exportTimeoutMillis: devmode ? devmodeExportInterval : productionExportInterval,
|
|
257
|
+
exportIntervalMillis: devmode ? devmodeExportInterval : productionExportInterval,
|
|
258
|
+
})
|
|
259
|
+
: undefined;
|
|
242
260
|
|
|
243
261
|
// Create a separate metric reader for the MeterProvider
|
|
244
|
-
const hostMetricReader =
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
: undefined;
|
|
262
|
+
const hostMetricReader = metricExporter
|
|
263
|
+
? new PeriodicExportingMetricReader({
|
|
264
|
+
exporter: metricExporter,
|
|
265
|
+
exportTimeoutMillis: devmode ? devmodeExportInterval : productionExportInterval,
|
|
266
|
+
exportIntervalMillis: devmode ? devmodeExportInterval : productionExportInterval,
|
|
267
|
+
})
|
|
268
|
+
: undefined;
|
|
252
269
|
|
|
253
270
|
const meterProvider = hostMetricReader
|
|
254
271
|
? new MeterProvider({
|
|
@@ -266,7 +283,7 @@ export function registerOtel(config: OtelConfig): OtelResponse {
|
|
|
266
283
|
let running = false;
|
|
267
284
|
let instrumentationSDK: NodeSDK | undefined;
|
|
268
285
|
|
|
269
|
-
if (url) {
|
|
286
|
+
if (url || useConsoleExporters) {
|
|
270
287
|
const propagator = new CompositePropagator({
|
|
271
288
|
propagators: [new W3CTraceContextPropagator(), new W3CBaggagePropagator()],
|
|
272
289
|
});
|
|
@@ -274,11 +291,8 @@ export function registerOtel(config: OtelConfig): OtelResponse {
|
|
|
274
291
|
|
|
275
292
|
instrumentFetch();
|
|
276
293
|
|
|
277
|
-
// Combine custom span processors with
|
|
278
|
-
const allSpanProcessors = [
|
|
279
|
-
...(traceSpanProcessor ? [traceSpanProcessor] : []),
|
|
280
|
-
...(config.spanProcessors || []),
|
|
281
|
-
];
|
|
294
|
+
// Combine custom span processors with our span processors
|
|
295
|
+
const allSpanProcessors = [...spanProcessors, ...(config.spanProcessors || [])];
|
|
282
296
|
|
|
283
297
|
instrumentationSDK = new NodeSDK({
|
|
284
298
|
logRecordProcessor: loggerProvider.processor,
|
|
@@ -47,25 +47,6 @@ function initializeTables(db: Database): void {
|
|
|
47
47
|
WHERE expires_at IS NOT NULL
|
|
48
48
|
`);
|
|
49
49
|
|
|
50
|
-
// Object Storage table
|
|
51
|
-
db.run(`
|
|
52
|
-
CREATE TABLE IF NOT EXISTS object_storage (
|
|
53
|
-
project_path TEXT NOT NULL,
|
|
54
|
-
bucket TEXT NOT NULL,
|
|
55
|
-
key TEXT NOT NULL,
|
|
56
|
-
data BLOB NOT NULL,
|
|
57
|
-
content_type TEXT NOT NULL DEFAULT 'application/octet-stream',
|
|
58
|
-
content_encoding TEXT,
|
|
59
|
-
cache_control TEXT,
|
|
60
|
-
content_disposition TEXT,
|
|
61
|
-
content_language TEXT,
|
|
62
|
-
metadata TEXT,
|
|
63
|
-
created_at INTEGER NOT NULL,
|
|
64
|
-
updated_at INTEGER NOT NULL,
|
|
65
|
-
PRIMARY KEY (project_path, bucket, key)
|
|
66
|
-
)
|
|
67
|
-
`);
|
|
68
|
-
|
|
69
50
|
// Stream Storage table
|
|
70
51
|
db.run(`
|
|
71
52
|
CREATE TABLE IF NOT EXISTS stream_storage (
|
|
@@ -125,9 +106,6 @@ function cleanupOrphanedProjects(db: Database): void {
|
|
|
125
106
|
const kvPaths = db.query('SELECT DISTINCT project_path FROM kv_storage').all() as Array<{
|
|
126
107
|
project_path: string;
|
|
127
108
|
}>;
|
|
128
|
-
const objectPaths = db.query('SELECT DISTINCT project_path FROM object_storage').all() as Array<{
|
|
129
|
-
project_path: string;
|
|
130
|
-
}>;
|
|
131
109
|
const streamPaths = db.query('SELECT DISTINCT project_path FROM stream_storage').all() as Array<{
|
|
132
110
|
project_path: string;
|
|
133
111
|
}>;
|
|
@@ -137,7 +115,7 @@ function cleanupOrphanedProjects(db: Database): void {
|
|
|
137
115
|
|
|
138
116
|
// Combine and deduplicate all project paths
|
|
139
117
|
const allPaths = new Set<string>();
|
|
140
|
-
[...kvPaths, ...
|
|
118
|
+
[...kvPaths, ...streamPaths, ...vectorPaths].forEach((row) => {
|
|
141
119
|
allPaths.add(row.project_path);
|
|
142
120
|
});
|
|
143
121
|
|
|
@@ -155,9 +133,6 @@ function cleanupOrphanedProjects(db: Database): void {
|
|
|
155
133
|
|
|
156
134
|
// Delete from all tables
|
|
157
135
|
const deleteKv = db.prepare(`DELETE FROM kv_storage WHERE project_path IN (${placeholders})`);
|
|
158
|
-
const deleteObject = db.prepare(
|
|
159
|
-
`DELETE FROM object_storage WHERE project_path IN (${placeholders})`
|
|
160
|
-
);
|
|
161
136
|
const deleteStream = db.prepare(
|
|
162
137
|
`DELETE FROM stream_storage WHERE project_path IN (${placeholders})`
|
|
163
138
|
);
|
|
@@ -166,7 +141,6 @@ function cleanupOrphanedProjects(db: Database): void {
|
|
|
166
141
|
);
|
|
167
142
|
|
|
168
143
|
deleteKv.run(...pathsToDelete);
|
|
169
|
-
deleteObject.run(...pathsToDelete);
|
|
170
144
|
deleteStream.run(...pathsToDelete);
|
|
171
145
|
deleteVector.run(...pathsToDelete);
|
|
172
146
|
|
|
@@ -8,52 +8,6 @@ export function createLocalStorageRouter(db: Database, projectPath: string): any
|
|
|
8
8
|
// so we can detect if we're running in local mode easily
|
|
9
9
|
router.get('/_agentuity/local/health', (c) => c.text('OK'));
|
|
10
10
|
|
|
11
|
-
// Serve objects: GET /_agentuity/local/object/:bucket/:key
|
|
12
|
-
router.get('/_agentuity/local/object/:bucket/:key', async (c) => {
|
|
13
|
-
const bucket = c.req.param('bucket');
|
|
14
|
-
const key = c.req.param('key');
|
|
15
|
-
|
|
16
|
-
const query = db.query(`
|
|
17
|
-
SELECT data, content_type, content_encoding, cache_control,
|
|
18
|
-
content_disposition, content_language
|
|
19
|
-
FROM object_storage
|
|
20
|
-
WHERE project_path = ? AND bucket = ? AND key = ?
|
|
21
|
-
`);
|
|
22
|
-
|
|
23
|
-
const row = query.get(projectPath, bucket, key) as {
|
|
24
|
-
data: Buffer;
|
|
25
|
-
content_type: string;
|
|
26
|
-
content_encoding: string | null;
|
|
27
|
-
cache_control: string | null;
|
|
28
|
-
content_disposition: string | null;
|
|
29
|
-
content_language: string | null;
|
|
30
|
-
} | null;
|
|
31
|
-
|
|
32
|
-
if (!row) {
|
|
33
|
-
return c.notFound();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Set headers
|
|
37
|
-
const headers: Record<string, string> = {
|
|
38
|
-
'Content-Type': row.content_type,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
if (row.content_encoding) {
|
|
42
|
-
headers['Content-Encoding'] = row.content_encoding;
|
|
43
|
-
}
|
|
44
|
-
if (row.cache_control) {
|
|
45
|
-
headers['Cache-Control'] = row.cache_control;
|
|
46
|
-
}
|
|
47
|
-
if (row.content_disposition) {
|
|
48
|
-
headers['Content-Disposition'] = row.content_disposition;
|
|
49
|
-
}
|
|
50
|
-
if (row.content_language) {
|
|
51
|
-
headers['Content-Language'] = row.content_language;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return c.body(new Uint8Array(row.data), 200, headers);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
11
|
// Serve streams: GET /_agentuity/local/stream/:id
|
|
58
12
|
router.get('/_agentuity/local/stream/:id', async (c) => {
|
|
59
13
|
const id = c.req.param('id');
|
|
@@ -2,6 +2,5 @@ export { getLocalDB, closeLocalDB } from './_db';
|
|
|
2
2
|
export { normalizeProjectPath, simpleEmbedding, cosineSimilarity } from './_util';
|
|
3
3
|
export { createLocalStorageRouter } from './_router';
|
|
4
4
|
export { LocalKeyValueStorage } from './keyvalue';
|
|
5
|
-
export { LocalObjectStorage } from './objectstore';
|
|
6
5
|
export { LocalStreamStorage } from './stream';
|
|
7
6
|
export { LocalVectorStorage } from './vector';
|
package/src/session.ts
CHANGED
|
@@ -30,7 +30,7 @@ type SessionEventCallback<T extends Session> = (
|
|
|
30
30
|
* @example
|
|
31
31
|
* ```typescript
|
|
32
32
|
* // Access thread in agent handler
|
|
33
|
-
* const agent = createAgent({
|
|
33
|
+
* const agent = createAgent('conversation', {
|
|
34
34
|
* handler: async (ctx, input) => {
|
|
35
35
|
* // Get thread ID
|
|
36
36
|
* ctx.logger.info('Thread: %s', ctx.thread.id);
|
|
@@ -135,7 +135,7 @@ export interface Thread {
|
|
|
135
135
|
*
|
|
136
136
|
* @example
|
|
137
137
|
* ```typescript
|
|
138
|
-
* const agent = createAgent({
|
|
138
|
+
* const agent = createAgent('request-handler', {
|
|
139
139
|
* handler: async (ctx, input) => {
|
|
140
140
|
* // Get session ID (unique per request)
|
|
141
141
|
* ctx.logger.info('Session: %s', ctx.session.id);
|