@agimon-ai/po-log 0.0.0-alpha.207 → 0.0.0-alpha.209

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.
@@ -1,7 +1,7 @@
1
- import { defineFill, defineNativePlugin, defineToolRenderer, t, useLocale, useT } from "@agimon-ai/po-core/native";
1
+ import { defineFill, defineNativePlugin, defineToolRenderer, useT } from "@agimon-ai/po-core/native";
2
2
  import { View } from "react-native-unistyles/components/native/View";
3
3
  import { Text } from "react-native-unistyles/components/native/Text";
4
- import { Badge, CodeBlock, MessageItem, MessageItemBody, MessageItemHeader, MessageItemStatus, SectionLabel, StatusBadge, collapseLines, fontOf, toolTone } from "@agimon-ai/po-native-components";
4
+ import { CodeBlock, MessageItem, MessageItemBody, MessageItemHeader, MessageItemStatus, fontOf, toolTone } from "@agimon-ai/po-native-components";
5
5
  import { StyleSheet } from "react-native-unistyles";
6
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
7
  //#endregion
@@ -35,501 +35,6 @@ var Logs_help_guides_native_default = defineFill({
35
35
  }
36
36
  });
37
37
  //#endregion
38
- //#region src/extensions/workspaces/sessions/(frontend)/tool/_lib/agentDiagnosticView.ts
39
- /** The diagnose_agent report as the card's lines: the tool's text output, blank lines dropped. */
40
- function diagnosticLines(output) {
41
- return output.split("\n").filter(Boolean);
42
- }
43
- /** Categories that are real failures of the run; the rest (caller errors, refusals, expected failures) are not. */
44
- const FAILURE_CATEGORIES = /* @__PURE__ */ new Set([
45
- "tool_failure",
46
- "infrastructure_failure",
47
- "api_error",
48
- "api_retries_exhausted",
49
- "log_error"
50
- ]);
51
- /** The sentence the empty state keeps from the report's limitations. */
52
- const EMPTY_SENTENCE = /[^.]*empty data[^.]*\.?/i;
53
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
54
- const count$1 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
55
- const text = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
56
- function categories(value) {
57
- if (!isRecord(value)) return [];
58
- return Object.entries(value).flatMap(([key, raw]) => {
59
- const n = count$1(raw);
60
- return n !== void 0 && n > 0 && key.trim() !== "" ? [{
61
- key,
62
- label: key.replaceAll("_", " "),
63
- count: n,
64
- failure: FAILURE_CATEGORIES.has(key)
65
- }] : [];
66
- }).sort((a, b) => b.count - a.count);
67
- }
68
- function tools(value) {
69
- if (!Array.isArray(value)) return [];
70
- return value.flatMap((raw) => {
71
- if (!isRecord(raw)) return [];
72
- const name = text(raw.name);
73
- if (name === void 0) return [];
74
- return [{
75
- name,
76
- invocations: count$1(raw.invocations),
77
- p90TurnTokens: count$1(raw.p90TurnTokens)
78
- }];
79
- });
80
- }
81
- /**
82
- * Parses the tool's JSON report at the card's boundary. Unknown or malformed
83
- * fields are skipped; output that is not a JSON object, or carries none of the
84
- * report's fields, returns null so the card falls back to the raw lines.
85
- */
86
- function parseDiagnosticReport(output) {
87
- let raw;
88
- try {
89
- raw = JSON.parse(output);
90
- } catch {
91
- return null;
92
- }
93
- if (!isRecord(raw)) return null;
94
- const usage = isRecord(raw.usage) ? raw.usage : {};
95
- const report = {
96
- scope: text(raw.scope),
97
- period: text(raw.period),
98
- evidence: text(raw.evidence),
99
- code: text(raw.code),
100
- capturedRecords: count$1(raw.capturedRecords),
101
- capturedIssues: count$1(raw.capturedIssues),
102
- categories: categories(raw.issuesByCategory),
103
- inputTokens: count$1(usage.inputTokens),
104
- outputTokens: count$1(usage.outputTokens),
105
- tokenCoveragePercent: count$1(usage.tokenCoveragePercent),
106
- tools: tools(raw.tools),
107
- limitReached: typeof raw.limitReached === "boolean" ? raw.limitReached : void 0,
108
- captureCompleteness: text(raw.captureCompleteness),
109
- limitations: text(raw.limitations)
110
- };
111
- return Object.values(report).some((value) => Array.isArray(value) ? value.length > 0 : value !== void 0) ? report : null;
112
- }
113
- /** Token counts in a few characters: 182400 reads `182.4k`. */
114
- function compactNumber(value, locale = "en") {
115
- if (locale !== "en") return new Intl.NumberFormat(locale, {
116
- notation: "compact",
117
- maximumFractionDigits: 1
118
- }).format(Math.round(value));
119
- if (value >= 1e6) return `${(value / 1e6).toFixed(1)}M`;
120
- if (value >= 1e3) return `${(value / 1e3).toFixed(1)}k`;
121
- return String(Math.round(value));
122
- }
123
- const words = (value) => value.replaceAll(/[-_]/g, " ");
124
- /** The header summary: the primary piece stays whole, the context may truncate. */
125
- function diagnosticSummary(t, report) {
126
- const context = [report.scope, report.period].flatMap((part) => part ? [words(part)] : []).join(" · ");
127
- const issues = report.capturedIssues;
128
- const primary = report.evidence === "unavailable" ? t("log.ui.telemetryUnavailable", "Telemetry unavailable") : report.evidence === "empty" ? t("log.ui.nothingCaptured", "Nothing captured") : issues === void 0 ? t("log.ui.capturedAgentEvidence", "Captured agent evidence") : issues === 0 ? t("log.ui.noIssues", "No issues") : issues === 1 ? t("log.ui.issueCountOne", "{count} issue", { count: issues }) : t("log.ui.issueCount", "{count} issues", { count: issues });
129
- return context === "" ? { primary } : {
130
- primary,
131
- context
132
- };
133
- }
134
- /** The key figures row; a figure the report did not send is left out rather than shown as zero. */
135
- function diagnosticFigures(t, report, locale = "en") {
136
- const figures = [];
137
- if (report.capturedRecords !== void 0) figures.push({
138
- label: t("log.ui.records", "Records"),
139
- value: report.capturedRecords.toLocaleString(locale),
140
- failure: false
141
- });
142
- if (report.capturedIssues !== void 0) {
143
- const failing = report.capturedIssues > 0 && report.categories.some((category) => category.failure);
144
- figures.push({
145
- label: t("log.ui.issues", "Issues"),
146
- value: report.capturedIssues.toLocaleString(locale),
147
- failure: failing
148
- });
149
- }
150
- if (report.inputTokens !== void 0 || report.outputTokens !== void 0) {
151
- const side = (value) => value === void 0 ? "?" : compactNumber(value, locale);
152
- figures.push({
153
- label: t("log.ui.tokensInOut", "Tokens in / out"),
154
- value: `${side(report.inputTokens)} / ${side(report.outputTokens)}`,
155
- failure: false
156
- });
157
- }
158
- if (report.tokenCoveragePercent !== void 0) figures.push({
159
- label: t("log.ui.tokenCoverage", "Token coverage"),
160
- value: `${String(report.tokenCoveragePercent)}%`,
161
- failure: false
162
- });
163
- return figures;
164
- }
165
- /** The quiet note at the bottom: capture completeness, then the report's limitations. */
166
- function diagnosticNote(t, report) {
167
- const parts = [report.captureCompleteness ? t("log.ui.captureCompleteness", "Capture completeness: {value}.", { value: words(report.captureCompleteness) }) : void 0, report.limitations].filter((part) => part !== void 0);
168
- return parts.length > 0 ? parts.join(" ") : void 0;
169
- }
170
- /** The limitation sentence an empty report leads with, so an empty window never reads as a healthy run. */
171
- function emptyLimitation(t, report) {
172
- return report.limitations?.match(EMPTY_SENTENCE)?.[0].trim() ?? t("log.ui.emptyDataIsNotProofOfAHealthyRun", "Empty data is not proof of a healthy run.");
173
- }
174
- //#endregion
175
- //#region src/extensions/workspaces/sessions/(frontend)/tool/_components/AgentDiagnosticCard.native.tsx
176
- const DEFAULT_SUMMARY = () => t("log.ui.capturedAgentEvidence", "Captured agent evidence");
177
- /**
178
- * The diagnose_agent tool's timeline item on native, as the web's: the report
179
- * as a header summary and its key figures, with categories, tools and the
180
- * limitations on expand. Output that does not parse keeps the raw lines. A
181
- * failed read shows only its reason in red; the header carries the failure.
182
- */
183
- function AgentDiagnosticCard({ toolName, output, running, isError }) {
184
- const t = useT();
185
- const tone = toolTone({
186
- running,
187
- isError
188
- });
189
- const report = running || isError ? null : parseDiagnosticReport(output);
190
- if (report) return /* @__PURE__ */ jsx(ReportCard, {
191
- toolName,
192
- tone,
193
- report
194
- });
195
- const lines = diagnosticLines(output);
196
- if (isError) return /* @__PURE__ */ jsxs(MessageItem, {
197
- tone,
198
- children: [/* @__PURE__ */ jsx(MessageItemHeader, {
199
- title: toolName,
200
- children: DEFAULT_SUMMARY()
201
- }), lines.length > 0 ? /* @__PURE__ */ jsx(MessageItemBody, { children: /* @__PURE__ */ jsx(Text, {
202
- selectable: true,
203
- style: [styles$1.sans, styles$1.error],
204
- children: lines.join("\n")
205
- }) }) : null]
206
- });
207
- return /* @__PURE__ */ jsx(MessageItem, {
208
- tone,
209
- expandable: lines.length > 12,
210
- children: ({ expanded }) => {
211
- const view = collapseLines(lines, 12, expanded);
212
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
213
- title: toolName,
214
- children: DEFAULT_SUMMARY()
215
- }), view.shown.length > 0 || running ? /* @__PURE__ */ jsxs(MessageItemBody, { children: [
216
- view.shown.map((line, index) => /* @__PURE__ */ jsx(Text, {
217
- selectable: true,
218
- style: [styles$1.sans, styles$1.text],
219
- children: line
220
- }, `${String(index)}-${line}`)),
221
- view.hidden > 0 ? /* @__PURE__ */ jsx(MessageItemStatus, {
222
- expands: true,
223
- children: t("log.ui.moreLines", "{count} more lines", { count: view.hidden })
224
- }) : null,
225
- running ? /* @__PURE__ */ jsx(MessageItemStatus, {
226
- tone: "running",
227
- children: t("log.ui.readingSessionTelemetry", "Reading session telemetry")
228
- }) : null
229
- ] }) : null] });
230
- }
231
- });
232
- }
233
- function ReportCard({ toolName, tone, report }) {
234
- const t = useT();
235
- const locale = useLocale();
236
- const summary = diagnosticSummary(t, report);
237
- const figures = diagnosticFigures(t, report, locale);
238
- const note = diagnosticNote(t, report);
239
- const empty = report.evidence === "empty";
240
- const unavailable = report.evidence === "unavailable";
241
- const sentence = emptyLimitation(t, report);
242
- const extraNote = empty && note === sentence ? void 0 : note;
243
- const quiet = empty || unavailable;
244
- const details = quiet ? extraNote !== void 0 : report.categories.length > 0 || report.tools.length > 0 || note !== void 0;
245
- return /* @__PURE__ */ jsx(MessageItem, {
246
- tone: unavailable ? "neutral" : tone,
247
- expandable: details,
248
- children: ({ expanded }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MessageItemHeader, {
249
- title: toolName,
250
- children: /* @__PURE__ */ jsx(View, {
251
- style: styles$1.summary,
252
- children: /* @__PURE__ */ jsx(Text, {
253
- numberOfLines: 1,
254
- style: [styles$1.sans, styles$1.primary],
255
- children: summary.primary
256
- })
257
- })
258
- }), /* @__PURE__ */ jsxs(MessageItemBody, {
259
- style: styles$1.body,
260
- children: [
261
- unavailable ? /* @__PURE__ */ jsxs(View, {
262
- style: styles$1.wrapRow,
263
- children: [/* @__PURE__ */ jsx(Text, {
264
- style: [styles$1.sans, styles$1.dim],
265
- children: t("log.ui.theSessionSTelemetryCouldNotBeRead", "The session's telemetry could not be read.")
266
- }), report.code ? /* @__PURE__ */ jsx(StatusBadge, {
267
- size: "xs",
268
- children: /* @__PURE__ */ jsx(Text, {
269
- style: styles$1.code,
270
- children: report.code
271
- })
272
- }) : null]
273
- }) : empty ? /* @__PURE__ */ jsxs(View, {
274
- style: styles$1.block,
275
- children: [/* @__PURE__ */ jsx(Text, {
276
- style: [styles$1.sans, styles$1.text],
277
- children: t("log.ui.noRecordsWereCapturedInThisWindow", "No records were captured in this window.")
278
- }), /* @__PURE__ */ jsx(Text, {
279
- style: [styles$1.small, styles$1.dim],
280
- children: sentence
281
- })]
282
- }) : figures.length > 0 ? /* @__PURE__ */ jsx(View, {
283
- style: styles$1.figures,
284
- children: figures.map((figure) => /* @__PURE__ */ jsxs(View, {
285
- style: styles$1.figure,
286
- children: [/* @__PURE__ */ jsx(Text, {
287
- numberOfLines: 1,
288
- style: [styles$1.small, styles$1.dim],
289
- children: figure.label
290
- }), /* @__PURE__ */ jsx(Text, {
291
- numberOfLines: 1,
292
- style: [styles$1.value, figure.failure ? styles$1.error : styles$1.hi],
293
- children: figure.value
294
- })]
295
- }, figure.label))
296
- }) : null,
297
- expanded && !quiet && report.categories.length > 0 ? /* @__PURE__ */ jsxs(View, {
298
- style: styles$1.section,
299
- children: [/* @__PURE__ */ jsx(SectionLabel, { children: t("log.ui.issuesByCategory", "Issues by category") }), /* @__PURE__ */ jsx(View, {
300
- style: styles$1.wrapRow,
301
- children: report.categories.map((category) => /* @__PURE__ */ jsxs(Badge, {
302
- tone: category.failure ? "red" : "neutral",
303
- children: [category.label, /* @__PURE__ */ jsx(Text, {
304
- style: [
305
- styles$1.small,
306
- styles$1.count,
307
- category.failure ? styles$1.error : styles$1.text
308
- ],
309
- children: String(category.count)
310
- })]
311
- }, category.key))
312
- })]
313
- }) : null,
314
- expanded && !quiet && report.tools.length > 0 ? /* @__PURE__ */ jsxs(View, {
315
- style: styles$1.section,
316
- children: [
317
- /* @__PURE__ */ jsx(SectionLabel, { children: t("log.ui.tools", "Tools") }),
318
- /* @__PURE__ */ jsxs(View, {
319
- style: styles$1.toolRow,
320
- children: [
321
- /* @__PURE__ */ jsx(Text, {
322
- style: [
323
- styles$1.small,
324
- styles$1.dim,
325
- styles$1.toolName
326
- ],
327
- children: t("log.ui.name", "Name")
328
- }),
329
- /* @__PURE__ */ jsx(Text, {
330
- style: [
331
- styles$1.small,
332
- styles$1.dim,
333
- styles$1.toolCalls
334
- ],
335
- children: t("log.ui.calls", "Calls")
336
- }),
337
- /* @__PURE__ */ jsx(Text, {
338
- style: [
339
- styles$1.small,
340
- styles$1.dim,
341
- styles$1.toolTokens
342
- ],
343
- children: t("log.ui.p90Turn", "p90 turn")
344
- })
345
- ]
346
- }),
347
- /* @__PURE__ */ jsx(View, { children: report.tools.map((tool) => /* @__PURE__ */ jsxs(View, {
348
- style: [styles$1.toolRow, styles$1.toolDivided],
349
- children: [
350
- /* @__PURE__ */ jsx(Text, {
351
- numberOfLines: 1,
352
- style: [
353
- styles$1.mono,
354
- styles$1.text,
355
- styles$1.toolName
356
- ],
357
- children: tool.name
358
- }),
359
- /* @__PURE__ */ jsx(Text, {
360
- style: [
361
- styles$1.sans,
362
- styles$1.text,
363
- styles$1.toolCalls
364
- ],
365
- children: tool.invocations === void 0 ? "?" : tool.invocations.toLocaleString(locale)
366
- }),
367
- /* @__PURE__ */ jsx(Text, {
368
- style: [
369
- styles$1.sans,
370
- styles$1.text,
371
- styles$1.toolTokens
372
- ],
373
- children: tool.p90TurnTokens === void 0 ? "?" : compactNumber(tool.p90TurnTokens, locale)
374
- })
375
- ]
376
- }, tool.name)) }),
377
- report.limitReached ? /* @__PURE__ */ jsx(Text, {
378
- style: [styles$1.small, styles$1.dim],
379
- children: t("log.ui.firstTools", "Showing the first {count} tools.", { count: report.tools.length })
380
- }) : null
381
- ]
382
- }) : null,
383
- expanded && extraNote ? /* @__PURE__ */ jsx(Text, {
384
- style: [styles$1.small, styles$1.faint],
385
- children: extraNote
386
- }) : null
387
- ]
388
- })] })
389
- });
390
- }
391
- /** Numbers line up down a column. */
392
- const TABULAR = ["tabular-nums"];
393
- /** The calls column fits four digits; the token column fits `182.4k`. */
394
- const CALLS_WIDTH = 48;
395
- const TOKENS_WIDTH = 72;
396
- const styles$1 = StyleSheet.create((theme) => ({
397
- summary: {
398
- flex: 1,
399
- flexDirection: "row",
400
- alignItems: "center",
401
- gap: theme.spacing(1.5),
402
- minWidth: 0,
403
- uni__dependencies: [0]
404
- },
405
- primary: {
406
- flexShrink: 1,
407
- color: theme.colors.text,
408
- uni__dependencies: [0]
409
- },
410
- body: {
411
- gap: theme.spacing(4),
412
- uni__dependencies: [0]
413
- },
414
- block: {
415
- gap: theme.spacing(1),
416
- uni__dependencies: [0]
417
- },
418
- section: {
419
- gap: theme.spacing(2),
420
- uni__dependencies: [0]
421
- },
422
- wrapRow: {
423
- flexDirection: "row",
424
- flexWrap: "wrap",
425
- alignItems: "center",
426
- gap: theme.spacing(2),
427
- uni__dependencies: [0]
428
- },
429
- figures: {
430
- flexDirection: "row",
431
- flexWrap: "wrap",
432
- rowGap: theme.spacing(3),
433
- uni__dependencies: [0]
434
- },
435
- figure: {
436
- width: "50%",
437
- gap: theme.spacing(.5),
438
- paddingRight: theme.spacing(2),
439
- uni__dependencies: [0]
440
- },
441
- toolRow: {
442
- flexDirection: "row",
443
- alignItems: "center",
444
- gap: theme.spacing(3),
445
- paddingVertical: theme.spacing(1),
446
- uni__dependencies: [0]
447
- },
448
- toolDivided: {
449
- borderTopWidth: 1,
450
- borderTopColor: theme.colors["border-soft"],
451
- uni__dependencies: [0]
452
- },
453
- toolName: {
454
- flex: 1,
455
- minWidth: 0
456
- },
457
- toolCalls: {
458
- width: CALLS_WIDTH,
459
- textAlign: "right",
460
- fontVariant: TABULAR
461
- },
462
- toolTokens: {
463
- width: TOKENS_WIDTH,
464
- textAlign: "right",
465
- fontVariant: TABULAR
466
- },
467
- sans: {
468
- fontFamily: fontOf(theme.fontFamily.sans),
469
- fontSize: theme.fontSize.base,
470
- lineHeight: theme.lineHeight.base,
471
- uni__dependencies: [0]
472
- },
473
- small: {
474
- fontFamily: fontOf(theme.fontFamily.sans),
475
- fontSize: theme.fontSize.sm,
476
- lineHeight: theme.lineHeight.sm,
477
- uni__dependencies: [0]
478
- },
479
- mono: {
480
- fontFamily: fontOf(theme.fontFamily.mono),
481
- fontSize: theme.fontSize.base,
482
- lineHeight: theme.lineHeight.base,
483
- uni__dependencies: [0]
484
- },
485
- code: {
486
- fontFamily: fontOf(theme.fontFamily.mono),
487
- fontSize: theme.fontSize.sm,
488
- lineHeight: theme.lineHeight.sm,
489
- color: theme.colors.faint,
490
- uni__dependencies: [0]
491
- },
492
- value: {
493
- fontFamily: fontOf(theme.fontFamily.sans),
494
- fontSize: theme.fontSize.lg,
495
- lineHeight: theme.lineHeight.lg,
496
- fontWeight: theme.fontWeight.semibold,
497
- fontVariant: TABULAR,
498
- uni__dependencies: [0]
499
- },
500
- count: {
501
- fontWeight: theme.fontWeight.semibold,
502
- fontVariant: TABULAR,
503
- uni__dependencies: [0]
504
- },
505
- text: {
506
- color: theme.colors.text,
507
- uni__dependencies: [0]
508
- },
509
- hi: {
510
- color: theme.colors.hi,
511
- uni__dependencies: [0]
512
- },
513
- dim: {
514
- color: theme.colors.dim,
515
- uni__dependencies: [0]
516
- },
517
- faint: {
518
- color: theme.colors.faint,
519
- uni__dependencies: [0]
520
- },
521
- error: {
522
- color: theme.colors.red,
523
- uni__dependencies: [0]
524
- }
525
- }));
526
- //#endregion
527
- //#region src/extensions/workspaces/sessions/(frontend)/tool/diagnose-agent.native.tsx
528
- var diagnose_agent_native_default = defineToolRenderer({
529
- tools: ["diagnose_agent"],
530
- message: AgentDiagnosticCard
531
- });
532
- //#endregion
533
38
  //#region src/extensions/workspaces/sessions/(frontend)/tool/_lib/logsinkToolRender.ts
534
39
  const logsinkToolNames = [
535
40
  "logsink_status",
@@ -888,7 +393,7 @@ const nativePlugin = defineNativePlugin({
888
393
  }, Logs_help_guides_native_default)];
889
394
  },
890
395
  get toolRenderers() {
891
- return [via({ tools: ["diagnose_agent"] }, diagnose_agent_native_default), via({ tools: ["logsink"] }, logsink_native_default)];
396
+ return [via({ tools: ["logsink"] }, logsink_native_default)];
892
397
  }
893
398
  }
894
399
  });