@agimon-ai/po-log 0.0.0-alpha.74 → 0.0.0-alpha.76
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.
|
@@ -170,6 +170,7 @@ function createLogsinkTool(method, operations) {
|
|
|
170
170
|
//#region src/services/logsinkNamespace/index.ts
|
|
171
171
|
const DECLARATIONS = `interface LogScope { kind: 'session' | 'history'; sessionId?: string; startTime?: string; endTime?: string }
|
|
172
172
|
interface LogResponse<T> { scope: LogScope; data: T }
|
|
173
|
+
interface LogPage { offset: number; limit: number; hasMore: boolean; nextOffset: number | null }
|
|
173
174
|
interface LogFilters {
|
|
174
175
|
scope?: 'session' | 'history'; sessionId?: string; startTime?: string; endTime?: string;
|
|
175
176
|
workflowRunId?: string; workflowName?: string; jobName?: string; jobId?: string;
|
|
@@ -183,7 +184,7 @@ interface LogRecord {
|
|
|
183
184
|
metadata: Record<string, unknown> | null; errorType: string | null; errorMessage: string | null;
|
|
184
185
|
[field: string]: unknown;
|
|
185
186
|
}
|
|
186
|
-
interface LogSearch { mode: 'filter' | 'fts'; count: number; total: number; truncated: boolean; results: LogRecord[] }
|
|
187
|
+
interface LogSearch { mode: 'filter' | 'fts'; count: number; total: number; truncated: boolean; results: LogRecord[]; pagination: LogPage }
|
|
187
188
|
interface LogIssue {
|
|
188
189
|
category: string; timestamp: string; service: string; sessionId: string | null; tool: string | null;
|
|
189
190
|
errorType: string | null; message: string; detail: string | null; fingerprint: string; occurrenceCount: number;
|
|
@@ -192,12 +193,12 @@ interface LogIssue {
|
|
|
192
193
|
interface LogIssues {
|
|
193
194
|
scanned: number; matchingLogs: number; truncated: boolean; coveragePercent: number; oldestScannedTimestamp: string | null;
|
|
194
195
|
totalIssues: number; uniqueIncidents: number; byCategory: Record<string, number>; byTool: Record<string, number>;
|
|
195
|
-
byErrorType: Record<string, number>; bySession: Record<string, number>; issues: LogIssue[];
|
|
196
|
+
byErrorType: Record<string, number>; bySession: Record<string, number>; issues: LogIssue[]; pagination: LogPage;
|
|
196
197
|
}
|
|
197
198
|
interface LogTraceEntry { timestamp: string; service: string; spanId: string | null; parentSpanId: string | null; level: string; message: string; [field: string]: unknown }
|
|
198
|
-
interface LogTrace { traceId: string; count: number; truncated: boolean; timeline: LogTraceEntry[] }
|
|
199
|
-
interface LogStats { groupBy: string; signalType: 'log' | 'span' | 'all'; totalEntries: number; statistics: { service: string; level: string; count: number }[] }
|
|
200
|
-
interface LogServices { count: number; truncated: boolean; services: string[] }
|
|
199
|
+
interface LogTrace { traceId: string; count: number; truncated: boolean; timeline: LogTraceEntry[]; pagination: LogPage }
|
|
200
|
+
interface LogStats { groupBy: string; signalType: 'log' | 'span' | 'all'; totalEntries: number; statistics: { service: string; level: string; count: number }[]; pagination: LogPage }
|
|
201
|
+
interface LogServices { count: number; truncated: boolean; services: string[]; pagination: LogPage }
|
|
201
202
|
interface LogTokens { inputTokens: number; outputTokens: number; totalTokens: number; cachedInputTokens: number; reasoningOutputTokens: number; usageEventCount: number }
|
|
202
203
|
interface LogTokenDistribution { samples: number; avgInputTokens: number; p50InputTokens: number; p90InputTokens: number; avgOutputTokens: number; p50OutputTokens: number; p90OutputTokens: number; avgTotalTokens: number; p50TotalTokens: number; p90TotalTokens: number }
|
|
203
204
|
interface LogMetrics {
|
|
@@ -207,22 +208,23 @@ interface LogMetrics {
|
|
|
207
208
|
groups: (LogTokens & { key: string; sessionId: string | null; issueCount: number; byCategory: Record<string, number>; [field: string]: unknown })[];
|
|
208
209
|
tools: { returnedTools: number; rows: { toolName: string; invocationCount: number; toolCallTurn: LogTokenDistribution; toolOutputImpact: LogTokenDistribution; [field: string]: unknown }[] };
|
|
209
210
|
timeline: (LogTokens & { bucketStart: string; label: string; totalRecords: number; issueCount: number })[];
|
|
211
|
+
pagination: { groups: LogPage; tools: LogPage; timeline: LogPage };
|
|
210
212
|
}
|
|
211
213
|
declare const logsink: {
|
|
212
214
|
/** Retained storage availability, not proof that the collector is capturing now. */
|
|
213
215
|
status(): Promise<LogResponse<LogAvailability>>;
|
|
214
|
-
/** Scoped structured query or FTS search. History requires explicit startTime/endTime. order is filter-only
|
|
215
|
-
search(input?: LogFilters & { query?: string; mode?: 'fts'; level?: string | string[]; traceId?: string; spanId?: string; errorType?: string; parentSessionId?: string; workflowId?: string; signalType?: 'log' | 'span'; limit?: number; order?: 'asc' | 'desc' }): Promise<LogResponse<LogSearch>>;
|
|
216
|
-
/**
|
|
217
|
-
agentIssues(input?: LogFilters & { limit?: number; scanLimit?: number }): Promise<LogResponse<LogIssues>>;
|
|
218
|
-
/** A bounded trace, filtered within scope before retrieval. */
|
|
219
|
-
trace(input: LogFilters & { traceId: string; limit?: number }): Promise<LogResponse<LogTrace>>;
|
|
220
|
-
/**
|
|
221
|
-
stats(input?: LogFilters & { groupBy?: 'level' | 'service' | 'both' | 'agent' | 'workflow' | 'job' | 'signal'; signalType?: 'log' | 'span' | 'all' }): Promise<LogResponse<LogStats>>;
|
|
222
|
-
/** Services that have retained records within scope. */
|
|
223
|
-
services(input?: LogFilters & { limit?: number }): Promise<LogResponse<LogServices>>;
|
|
224
|
-
/** Captured usage and tool turn costs, not exclusive per-tool token shares. */
|
|
225
|
-
metrics(input?: LogFilters & { model?: string | string[]; provider?: string | string[]; groupBy?: 'session' | 'workflow-run' | 'workflow-name' | 'job' | 'step' | 'agent' | 'model' | 'provider'; sort?: 'last-seen' | 'total-tokens' | 'issues'; toolSort?: 'p90-total-tokens' | 'avg-total-tokens' | 'invocations'; limit?: number; toolLimit?: number; period?: 'day' | 'week' | 'month' | 'all'; bucket?: 'hour' | 'day' | 'week' | 'month' }): Promise<LogResponse<LogMetrics>>;
|
|
216
|
+
/** Scoped structured query or FTS search. History requires explicit startTime/endTime. order is filter-only. Pages default to limit 100 (max 1000), offset 0. Continue with pagination.nextOffset and unchanged filters; live data is not a snapshot. Oversized results are refused: lower limits or narrow the window. */
|
|
217
|
+
search(input?: LogFilters & { query?: string; mode?: 'fts'; level?: string | string[]; traceId?: string; spanId?: string; errorType?: string; parentSessionId?: string; workflowId?: string; signalType?: 'log' | 'span'; limit?: number; offset?: number; order?: 'asc' | 'desc' }): Promise<LogResponse<LogSearch>>;
|
|
218
|
+
/** Pages deduplicated incidents, not scan coverage. Totals cover the whole bounded scan; truncated describes that scan. */
|
|
219
|
+
agentIssues(input?: LogFilters & { limit?: number; offset?: number; scanLimit?: number }): Promise<LogResponse<LogIssues>>;
|
|
220
|
+
/** A bounded trace page, filtered within scope before retrieval. */
|
|
221
|
+
trace(input: LogFilters & { traceId: string; limit?: number; offset?: number }): Promise<LogResponse<LogTrace>>;
|
|
222
|
+
/** Pages counts by level, service, agent, workflow, job or signal. totalEntries covers all matching groups. */
|
|
223
|
+
stats(input?: LogFilters & { groupBy?: 'level' | 'service' | 'both' | 'agent' | 'workflow' | 'job' | 'signal'; signalType?: 'log' | 'span' | 'all'; limit?: number; offset?: number }): Promise<LogResponse<LogStats>>;
|
|
224
|
+
/** Services that have retained records within scope, alphabetically paged. */
|
|
225
|
+
services(input?: LogFilters & { limit?: number; offset?: number }): Promise<LogResponse<LogServices>>;
|
|
226
|
+
/** Captured usage and tool turn costs, not exclusive per-tool token shares. Independently pages groups (limit/offset, default 50), tools (toolLimit/toolOffset, default 20), timeline (timelineLimit/timelineOffset, default 100). Totals cover the full scope. */
|
|
227
|
+
metrics(input?: LogFilters & { model?: string | string[]; provider?: string | string[]; groupBy?: 'session' | 'workflow-run' | 'workflow-name' | 'job' | 'step' | 'agent' | 'model' | 'provider'; sort?: 'last-seen' | 'total-tokens' | 'issues'; toolSort?: 'p90-total-tokens' | 'avg-total-tokens' | 'invocations'; limit?: number; offset?: number; toolLimit?: number; toolOffset?: number; timelineLimit?: number; timelineOffset?: number; period?: 'day' | 'week' | 'month' | 'all'; bucket?: 'hour' | 'day' | 'week' | 'month' }): Promise<LogResponse<LogMetrics>>;
|
|
226
228
|
};`;
|
|
227
229
|
const MAX_TRANSCRIPT_JSON = 12e3;
|
|
228
230
|
const TRANSCRIPT_LIST_SIZES = [
|
|
@@ -235,8 +237,11 @@ const RECORD_LISTS = /* @__PURE__ */ new Set([
|
|
|
235
237
|
"timeline",
|
|
236
238
|
"issues",
|
|
237
239
|
"groups",
|
|
238
|
-
"rows"
|
|
240
|
+
"rows",
|
|
241
|
+
"statistics",
|
|
242
|
+
"services"
|
|
239
243
|
]);
|
|
244
|
+
const RUN_DISPOSED = "Log Sink run is disposed.";
|
|
240
245
|
function cutLists(value, size) {
|
|
241
246
|
if (Array.isArray(value)) return value.map((item) => cutLists(item, size));
|
|
242
247
|
if (value === null || typeof value !== "object") return value;
|
|
@@ -249,7 +254,7 @@ function transcriptCopy(result) {
|
|
|
249
254
|
for (const size of TRANSCRIPT_LIST_SIZES) {
|
|
250
255
|
const kept = {
|
|
251
256
|
...cutLists(JSON.parse(json), size),
|
|
252
|
-
note: `Transcript copy keeps at most ${size} items per record list; the script received every record.`
|
|
257
|
+
note: `Transcript copy keeps at most ${size} items per record list; the script received every record in the requested page.`
|
|
253
258
|
};
|
|
254
259
|
if (JSON.stringify(kept).length <= MAX_TRANSCRIPT_JSON) return kept;
|
|
255
260
|
}
|
|
@@ -265,12 +270,12 @@ function createLogsinkNamespace(operations) {
|
|
|
265
270
|
const controller = new AbortController();
|
|
266
271
|
run.onDispose(() => {
|
|
267
272
|
disposed = true;
|
|
268
|
-
controller.abort(/* @__PURE__ */ new Error(
|
|
273
|
+
controller.abort(/* @__PURE__ */ new Error(RUN_DISPOSED));
|
|
269
274
|
});
|
|
270
275
|
const signal = AbortSignal.any([run.signal, controller.signal]);
|
|
271
276
|
const check = () => {
|
|
272
277
|
signal.throwIfAborted();
|
|
273
|
-
if (disposed) throw new Error(
|
|
278
|
+
if (disposed) throw new Error(RUN_DISPOSED);
|
|
274
279
|
};
|
|
275
280
|
const members = Object.create(null);
|
|
276
281
|
for (const method of LOGSINK_METHODS) members[method] = async (input = {}) => {
|