@felan-ai/ext-powerline 0.12.0 → 0.14.0
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 +101 -69
- package/dist/config.d.ts +4 -51
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -184
- package/dist/config.js.map +1 -1
- package/dist/core-services.d.ts +5 -0
- package/dist/core-services.d.ts.map +1 -0
- package/dist/core-services.js +66 -0
- package/dist/core-services.js.map +1 -0
- package/dist/data.d.ts +60 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +40 -0
- package/dist/data.js.map +1 -0
- package/dist/extension.d.ts +7 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +23 -0
- package/dist/extension.js.map +1 -0
- package/dist/generic.d.ts +8 -0
- package/dist/generic.d.ts.map +1 -0
- package/dist/generic.js +130 -0
- package/dist/generic.js.map +1 -0
- package/dist/git.d.ts +7 -2
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +32 -8
- package/dist/git.js.map +1 -1
- package/dist/index.d.ts +5 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -142
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +32 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +215 -0
- package/dist/runtime.js.map +1 -0
- package/dist/subscription.d.ts +5 -6
- package/dist/subscription.d.ts.map +1 -1
- package/dist/subscription.js +81 -39
- package/dist/subscription.js.map +1 -1
- package/dist/usage.d.ts +4 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +20 -0
- package/dist/usage.js.map +1 -0
- package/package.json +20 -10
- package/dist/colors.d.ts +0 -18
- package/dist/colors.d.ts.map +0 -1
- package/dist/colors.js +0 -42
- package/dist/colors.js.map +0 -1
- package/dist/footer.d.ts +0 -37
- package/dist/footer.d.ts.map +0 -1
- package/dist/footer.js +0 -146
- package/dist/footer.js.map +0 -1
- package/dist/segments.d.ts +0 -39
- package/dist/segments.d.ts.map +0 -1
- package/dist/segments.js +0 -337
- package/dist/segments.js.map +0 -1
- package/dist/symbols.d.ts +0 -27
- package/dist/symbols.d.ts.map +0 -1
- package/dist/symbols.js +0 -17
- package/dist/symbols.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,106 +1,138 @@
|
|
|
1
1
|
# @felan-ai/ext-powerline
|
|
2
2
|
|
|
3
|
-
Portable
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Portable Powerline data for client-owned footers. The package
|
|
4
|
+
root publishes generic `pi.ui` views and typed statuses in TUI, ACP, and headless
|
|
5
|
+
sessions without requiring a presentation service. Optional usage providers add
|
|
6
|
+
Codex, Claude, or Grok subscription usage and estimated savings. Footer
|
|
7
|
+
construction remains client-side.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
Published data includes:
|
|
8
10
|
|
|
9
11
|
- current directory
|
|
10
12
|
- cached Git branch, revision, working-tree status, tag, age, stash, upstream, and repository name
|
|
11
13
|
- active model and thinking level
|
|
12
|
-
- session token and cost totals (
|
|
13
|
-
and
|
|
14
|
+
- session token and cost totals (a configured usage provider can include root
|
|
15
|
+
and child sessions; without one, totals cover the active session only)
|
|
14
16
|
- active Codex, Claude, or Grok subscription usage
|
|
15
17
|
- estimated API-equivalent Felan savings for the configured recent-day period
|
|
16
18
|
- context-window usage
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
and
|
|
28
|
-
`
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Powerline
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
- the Felan version when supplied by the host application
|
|
20
|
+
|
|
21
|
+
Clients choose formatting, symbols, layout, styles, charsets and colors. Git probes
|
|
22
|
+
are asynchronous, cached, coalesced, time-bounded, and executed exclusively
|
|
23
|
+
through `pi.exec`.
|
|
24
|
+
|
|
25
|
+
The default entry publishes on `session_start` and refreshes for model,
|
|
26
|
+
thinking, agent, turn, tool, compaction, tree, and usage events, plus a 60-second refresh. Its generic
|
|
27
|
+
views publish structured segment values, semantic kinds and color roles, without
|
|
28
|
+
preformatted footer text, symbols, style or layout. Session
|
|
29
|
+
and context metrics also use typed token, percent, and USD statuses. The
|
|
30
|
+
optional `felan.powerline@3.0.0` hint changes presentation only; clients without
|
|
31
|
+
it can display the same columns, rows, and values. Other extensions' common UI
|
|
32
|
+
statuses remain separately available to clients rather than being copied into
|
|
33
|
+
Powerline through a feature service.
|
|
34
|
+
|
|
35
|
+
Shutdown aborts Git probes, usage requests, and pending publication requests,
|
|
36
|
+
joins owned work, closes views, and removes statuses. A failed publication stops
|
|
37
|
+
refresh timers and preserves a sanitized cleanup failure. Felan's client installs
|
|
38
|
+
the optional footer; the extension never constructs terminal components.
|
|
39
|
+
|
|
40
|
+
Semantic color roles let clients apply their own themes; the extension owns no
|
|
41
|
+
terminal palette or theme settings.
|
|
34
42
|
|
|
35
43
|
## Configuration
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
settings. The settings include scalar display fields and ordered `lines` with
|
|
39
|
-
supported segment objects. Theme selection and colors belong to Pi.
|
|
45
|
+
The extension declares only data-collection settings under `extensionConfig.powerline`:
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
```json
|
|
48
|
+
{ "showWorkingTree": true, "showStashCount": false, "periodDays": 7, "maxWindows": 3 }
|
|
49
|
+
```
|
|
44
50
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
Felan's TUI owns style, charset, wrapping, padding, ordered lines, alignment,
|
|
52
|
+
color roles and per-segment display choices under `presentation.powerline` in
|
|
53
|
+
`$FELAN_AGENT_DIR/tui/settings.json`. It reads released display settings as a
|
|
54
|
+
read-only fallback. These preferences never configure the daemon. `/settings`
|
|
55
|
+
separates display preferences from execution settings; the old display CLI flags
|
|
56
|
+
remain TUI-only launch overrides.
|
|
57
|
+
|
|
58
|
+
The extension publishes a `version` value when the host supplies one. Clients
|
|
59
|
+
decide whether and where to display it. The default Felan TUI footer does not
|
|
60
|
+
include a version segment.
|
|
61
|
+
|
|
62
|
+
The `subscription` segment supports native OpenAI ChatGPT, Codex, Claude, and
|
|
63
|
+
Grok SuperGrok / X Premium OAuth plans. ChatGPT, Codex, and Grok values show
|
|
64
|
+
remaining percentage; Claude values show used percentage. Native OpenAI usage
|
|
65
|
+
requires both an OpenAI ChatGPT OAuth login and a separate Codex OAuth login
|
|
66
|
+
for the same ChatGPT account/workspace (`/login openai-codex`). ChatGPT values
|
|
67
|
+
show shared-plan primary/secondary windows only; app-specific quotas are not
|
|
68
|
+
displayed. The host uses Codex credentials only for the companion ChatGPT usage
|
|
69
|
+
endpoints; it never sends native OpenAI tokens to ChatGPT backend endpoints.
|
|
70
|
+
These companion endpoints are undocumented. If the Codex companion is missing
|
|
71
|
+
or its app registration cannot be matched, the published data reports companion unavailability; clients can display
|
|
72
|
+
`ChatGPT usage: web only`; users can review usage at
|
|
73
|
+
<https://chatgpt.com/settings/usage>. App-registration matching is a safeguard,
|
|
74
|
+
not independent proof that the accounts match. Native OpenAI usage is
|
|
75
|
+
session-local and is not persisted/shared with Codex usage. The segment can
|
|
76
|
+
configure `showProviderName`, `showReset`,
|
|
77
|
+
`showPercentage` in the TUI. Extension `maxWindows` bounds published windows. It refreshes at startup, after turns and
|
|
49
78
|
model changes, and once per minute. Only model changes bypass the 30-second
|
|
50
|
-
minimum between requests.
|
|
51
|
-
`Retry-After` or an exponential backoff from
|
|
52
|
-
segment keeps showing the last successful
|
|
53
|
-
passed. Hosts can pass a `subscriptionStore`,
|
|
54
|
-
persistence, to share those values, the latest
|
|
55
|
-
sessions, restarts, and processes. A host that coordinates processes returns
|
|
56
|
-
`REFRESH_DEFERRED` when another process owns the refresh; the
|
|
57
|
-
the shared values.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
79
|
+
minimum between requests. For Codex, Claude, and Grok, after HTTP 429 every
|
|
80
|
+
refresh waits for the provider's `Retry-After` or an exponential backoff from
|
|
81
|
+
one minute up to 30 minutes, and the segment keeps showing the last successful
|
|
82
|
+
values whose reset time has not passed. Hosts can pass a `subscriptionStore`,
|
|
83
|
+
optionally backed by host-owned persistence, to share those values, the latest
|
|
84
|
+
error, and the backoff across sessions, restarts, and processes. A host that coordinates processes returns
|
|
85
|
+
`REFRESH_DEFERRED` when another process owns the refresh; the extension then publishes
|
|
86
|
+
the shared values. Native OpenAI values are neither persisted nor shared across
|
|
87
|
+
sessions and clear to the web-only fallback when companion validation fails.
|
|
88
|
+
The controller calls `releaseRefreshLease` when the model changes provider or
|
|
89
|
+
the session shuts down.
|
|
90
|
+
|
|
91
|
+
Felan's TUI enables the `savings` segment by default at the end of the first line; it is
|
|
61
92
|
right-aligned above the model. It reports estimated API-equivalent savings
|
|
62
93
|
across all retained local Felan activity for seven inclusive UTC calendar days
|
|
63
94
|
(today plus the six previous days), displayed as
|
|
64
|
-
`Est. Savings(7d): $33.00`. Set `periodDays`
|
|
95
|
+
`Est. Savings(7d): $33.00`. Set extension `periodDays` to choose another
|
|
65
96
|
period. A `~` before the amount means at least one measurement had unavailable
|
|
66
|
-
pricing, so the USD total is incomplete. The
|
|
97
|
+
pricing, so the USD total is incomplete. The configured usage provider supplies the query;
|
|
67
98
|
the portable package does not access storage itself.
|
|
68
99
|
|
|
69
|
-
|
|
70
|
-
options and `/settings`; structured `lines` values
|
|
71
|
-
`settings.json` or `/settings`.
|
|
100
|
+
Display settings are available through TUI-only `felan --powerline-*`
|
|
101
|
+
options and `/settings`; structured `lines` values live in `tui/settings.json`.
|
|
72
102
|
|
|
73
|
-
The package default export
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
provider detection, response parsing, caching, throttling, and rendering; the
|
|
103
|
+
The package default export obtains optional Models, Usage and Sessions services.
|
|
104
|
+
The portable package owns
|
|
105
|
+
provider detection, response parsing, caching, and throttling; the
|
|
77
106
|
host owns credential access and provider requests.
|
|
78
107
|
|
|
79
|
-
|
|
80
|
-
width-aware rows after the configured powerline status lines.
|
|
81
|
-
|
|
82
|
-
Felan's local TUI supplies a host backed by `ModelRuntime`. It uses the active
|
|
108
|
+
A local host can supply usage backed by `ModelRuntime`. It uses the active
|
|
83
109
|
provider's Felan OAuth credential and fixed Codex, Anthropic, or xAI Grok Build
|
|
84
110
|
billing endpoints. The extension package does not inspect authentication files,
|
|
85
111
|
receive stored credential objects, or perform network requests.
|
|
86
112
|
|
|
87
113
|
## Package boundary and requirements
|
|
88
114
|
|
|
89
|
-
|
|
90
|
-
import { createPowerlineExtension } from '@felan-ai/ext-powerline';
|
|
115
|
+
The root uses optional Agent Core services:
|
|
91
116
|
|
|
92
|
-
|
|
93
|
-
|
|
117
|
+
- `felan.models@1` supplies authenticated subscription usage without exposing credentials; the provider shares caching and rate-limit backoff across sessions.
|
|
118
|
+
- `felan.usage@1` supplies savings summaries.
|
|
119
|
+
- `felan.sessions@1` supplies execution usage totals and execution change events.
|
|
120
|
+
- `pi.runtime.host` supplies host version metadata without exposing a runtime factory.
|
|
121
|
+
|
|
122
|
+
There is no Powerline-specific service. Omitting optional services leaves normal
|
|
123
|
+
session/model/context data intact and omits unavailable subscription and
|
|
124
|
+
savings segments. The root exports portable runtime APIs plus the service-backed
|
|
125
|
+
default; `./runtime` exposes explicit runtime composition and `./data` exposes
|
|
126
|
+
normalized records. Neither loads footer implementations or Pi-TUI. The package
|
|
127
|
+
exports no TUI or view entrypoint; native footer rendering belongs to `apps/felan`.
|
|
94
128
|
|
|
95
|
-
The package owns
|
|
96
|
-
|
|
97
|
-
own
|
|
98
|
-
|
|
99
|
-
subscription work.
|
|
129
|
+
The package owns data validation, Git-cache behavior, provider detection,
|
|
130
|
+
response parsing, caching, and throttling. Hosts own credential access and provider
|
|
131
|
+
requests. Clients own rendering, symbols, layout and extra footer rows; generic data collection and
|
|
132
|
+
publication are not gated by client mode or the presence of a footer.
|
|
100
133
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
and Pi-TUI.
|
|
134
|
+
Configured hosts select this package through their extension list. The package
|
|
135
|
+
requires a compatible `@felan-ai/agent-core` peer.
|
|
104
136
|
|
|
105
137
|
## Development
|
|
106
138
|
|
package/dist/config.d.ts
CHANGED
|
@@ -1,54 +1,7 @@
|
|
|
1
|
-
export type FooterStyle = 'minimal' | 'powerline' | 'capsule';
|
|
2
|
-
export type Charset = 'unicode' | 'text';
|
|
3
|
-
export type DirectoryStyle = 'full' | 'fish' | 'basename';
|
|
4
|
-
export type SessionDisplayType = 'cost' | 'tokens' | 'both' | 'breakdown';
|
|
5
|
-
export type ContextDisplayStyle = 'text' | 'bar' | 'blocks' | 'blocks-line' | 'dots';
|
|
6
|
-
export type SegmentAlignment = 'left' | 'right';
|
|
7
|
-
export type SegmentName = 'directory' | 'git' | 'model' | 'session' | 'subscription' | 'savings' | 'context' | 'status' | 'version';
|
|
8
|
-
export type ThemeColorKey = SegmentName | 'warning' | 'critical' | 'muted' | 'extensionStatus1' | 'extensionStatus2' | 'extensionStatus3' | 'extensionStatus4';
|
|
9
|
-
export interface SegmentConfig {
|
|
10
|
-
enabled: boolean;
|
|
11
|
-
align?: SegmentAlignment;
|
|
12
|
-
style?: DirectoryStyle;
|
|
13
|
-
showSha?: boolean;
|
|
14
|
-
showWorkingTree?: boolean;
|
|
15
|
-
showTag?: boolean;
|
|
16
|
-
showTimeSinceCommit?: boolean;
|
|
17
|
-
showStashCount?: boolean;
|
|
18
|
-
showUpstream?: boolean;
|
|
19
|
-
showRepoName?: boolean;
|
|
20
|
-
type?: SessionDisplayType;
|
|
21
|
-
displayStyle?: ContextDisplayStyle;
|
|
22
|
-
showPercentageOnly?: boolean;
|
|
23
|
-
showTokensOnly?: boolean;
|
|
24
|
-
showProviderName?: boolean;
|
|
25
|
-
showReset?: boolean;
|
|
26
|
-
showPercentage?: boolean;
|
|
27
|
-
maxWindows?: number;
|
|
28
|
-
periodDays?: number;
|
|
29
|
-
width?: number;
|
|
30
|
-
warningThreshold?: number;
|
|
31
|
-
criticalThreshold?: number;
|
|
32
|
-
}
|
|
33
|
-
export interface DisplayLineConfig {
|
|
34
|
-
segments: Partial<Record<SegmentName, SegmentConfig>>;
|
|
35
|
-
}
|
|
36
|
-
export interface PowerlineConfig {
|
|
37
|
-
display: {
|
|
38
|
-
style: FooterStyle;
|
|
39
|
-
charset: Charset;
|
|
40
|
-
autoWrap: boolean;
|
|
41
|
-
padding: number;
|
|
42
|
-
lines: DisplayLineConfig[];
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export declare const DEFAULT_CONFIG: PowerlineConfig;
|
|
46
1
|
export declare const POWERLINE_CONFIG: import("@felan-ai/agent-core").ExtensionConfigDefinition<{
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
49
|
-
readonly
|
|
50
|
-
readonly
|
|
51
|
-
readonly lines: import("@felan-ai/agent-core").ExtensionConfigField<DisplayLineConfig[]>;
|
|
2
|
+
readonly showWorkingTree: import("@felan-ai/agent-core").ExtensionConfigField<boolean>;
|
|
3
|
+
readonly showStashCount: import("@felan-ai/agent-core").ExtensionConfigField<boolean>;
|
|
4
|
+
readonly periodDays: import("@felan-ai/agent-core").ExtensionConfigField<number>;
|
|
5
|
+
readonly maxWindows: import("@felan-ai/agent-core").ExtensionConfigField<number>;
|
|
52
6
|
}>;
|
|
53
|
-
export declare function powerlineConfigFromSettings(values: Readonly<Record<string, unknown>>): PowerlineConfig;
|
|
54
7
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB;;;;;EAS3B,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1,189 +1,12 @@
|
|
|
1
1
|
import { configField, defineExtensionConfig } from '@felan-ai/agent-core';
|
|
2
|
-
export const DEFAULT_CONFIG = {
|
|
3
|
-
display: {
|
|
4
|
-
style: 'minimal',
|
|
5
|
-
charset: 'text',
|
|
6
|
-
autoWrap: true,
|
|
7
|
-
padding: 1,
|
|
8
|
-
lines: [
|
|
9
|
-
{
|
|
10
|
-
segments: {
|
|
11
|
-
directory: { enabled: true, style: 'fish' },
|
|
12
|
-
git: { enabled: true, showSha: false, showWorkingTree: true },
|
|
13
|
-
savings: { enabled: true, align: 'right', periodDays: 7 },
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
segments: {
|
|
18
|
-
context: { enabled: true, displayStyle: 'text', showTokensOnly: true },
|
|
19
|
-
session: { enabled: true, type: 'cost' },
|
|
20
|
-
subscription: { enabled: true, showProviderName: false, showReset: true, maxWindows: 3 },
|
|
21
|
-
model: { enabled: true, align: 'right' },
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
segments: {
|
|
26
|
-
status: { enabled: true },
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
const STYLES = new Set(['minimal', 'powerline', 'capsule']);
|
|
33
|
-
const CHARSETS = new Set(['unicode', 'text']);
|
|
34
|
-
const DIRECTORY_STYLES = new Set(['full', 'fish', 'basename']);
|
|
35
|
-
const SESSION_TYPES = new Set(['cost', 'tokens', 'both', 'breakdown']);
|
|
36
|
-
const CONTEXT_STYLES = new Set(['text', 'bar', 'blocks', 'blocks-line', 'dots']);
|
|
37
|
-
const ALIGNMENTS = new Set(['left', 'right']);
|
|
38
|
-
const SEGMENT_NAMES = new Set(['directory', 'git', 'model', 'session', 'subscription', 'savings', 'context', 'status', 'version']);
|
|
39
|
-
const BOOLEAN_SEGMENT_FIELDS = [
|
|
40
|
-
'showSha',
|
|
41
|
-
'showWorkingTree',
|
|
42
|
-
'showTag',
|
|
43
|
-
'showTimeSinceCommit',
|
|
44
|
-
'showStashCount',
|
|
45
|
-
'showUpstream',
|
|
46
|
-
'showRepoName',
|
|
47
|
-
'showPercentageOnly',
|
|
48
|
-
'showTokensOnly',
|
|
49
|
-
'showProviderName',
|
|
50
|
-
'showReset',
|
|
51
|
-
'showPercentage',
|
|
52
|
-
];
|
|
53
|
-
const NUMBER_SEGMENT_FIELDS = ['maxWindows', 'periodDays', 'width', 'warningThreshold', 'criticalThreshold'];
|
|
54
2
|
export const POWERLINE_CONFIG = defineExtensionConfig({
|
|
55
|
-
id: 'powerline',
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
lines: configField.json({ default: DEFAULT_CONFIG.display.lines, description: 'Ordered powerline lines and segments', validate: validateLines }),
|
|
3
|
+
id: 'powerline', title: 'Powerline', fields: {
|
|
4
|
+
showWorkingTree: configField.boolean({ default: true, description: 'Collect Git working-tree changes' }),
|
|
5
|
+
showStashCount: configField.boolean({ default: false, description: 'Collect Git stash count' }),
|
|
6
|
+
periodDays: configField.number({ default: 7, description: 'Savings query period in days',
|
|
7
|
+
validate: value => Number.isSafeInteger(value) && Number(value) >= 1 && Number(value) <= 3650 ? undefined : 'must be an integer from 1 to 3650' }),
|
|
8
|
+
maxWindows: configField.number({ default: 3, description: 'Maximum subscription usage windows',
|
|
9
|
+
validate: value => Number.isSafeInteger(value) && Number(value) >= 1 && Number(value) <= 8 ? undefined : 'must be an integer from 1 to 8' }),
|
|
63
10
|
},
|
|
64
11
|
});
|
|
65
|
-
export function powerlineConfigFromSettings(values) {
|
|
66
|
-
const config = cloneConfig(DEFAULT_CONFIG);
|
|
67
|
-
if (typeof values.style === 'string' && STYLES.has(values.style))
|
|
68
|
-
config.display.style = values.style;
|
|
69
|
-
if (typeof values.charset === 'string' && CHARSETS.has(values.charset))
|
|
70
|
-
config.display.charset = values.charset;
|
|
71
|
-
if (typeof values.autoWrap === 'boolean')
|
|
72
|
-
config.display.autoWrap = values.autoWrap;
|
|
73
|
-
if (typeof values.padding === 'number')
|
|
74
|
-
config.display.padding = values.padding;
|
|
75
|
-
if (values.lines !== undefined)
|
|
76
|
-
config.display.lines = parseDisplayLines(values.lines);
|
|
77
|
-
return config;
|
|
78
|
-
}
|
|
79
|
-
function cloneConfig(config) {
|
|
80
|
-
return {
|
|
81
|
-
display: {
|
|
82
|
-
...config.display,
|
|
83
|
-
lines: config.display.lines.map((line) => ({
|
|
84
|
-
segments: Object.fromEntries(Object.entries(line.segments).map(([name, segment]) => [name, segment ? { ...segment } : segment])),
|
|
85
|
-
})),
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function validatePadding(value) {
|
|
90
|
-
return typeof value === 'number' && Number.isFinite(value) && value >= 0
|
|
91
|
-
? undefined
|
|
92
|
-
: 'must be a finite non-negative number';
|
|
93
|
-
}
|
|
94
|
-
function validateLines(value) {
|
|
95
|
-
try {
|
|
96
|
-
parseDisplayLines(value);
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
return errorMessage(error);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function parseDisplayLines(value) {
|
|
104
|
-
if (!Array.isArray(value))
|
|
105
|
-
throw new Error('must be an array');
|
|
106
|
-
return value.map((line, index) => parseDisplayLine(line, `lines[${index}]`));
|
|
107
|
-
}
|
|
108
|
-
function parseDisplayLine(value, source) {
|
|
109
|
-
const segments = {};
|
|
110
|
-
if (!isRecord(value))
|
|
111
|
-
throw new Error(`${source} must be an object`);
|
|
112
|
-
if (!isRecord(value.segments))
|
|
113
|
-
throw new Error(`${source}.segments must be an object`);
|
|
114
|
-
for (const [name, segment] of Object.entries(value.segments)) {
|
|
115
|
-
if (!SEGMENT_NAMES.has(name))
|
|
116
|
-
throw new Error(`${source}.segments contains unknown segment: ${name}`);
|
|
117
|
-
const parsed = parseSegmentConfig(segment, `${source}.segments.${name}`);
|
|
118
|
-
segments[name] = parsed;
|
|
119
|
-
}
|
|
120
|
-
return { segments };
|
|
121
|
-
}
|
|
122
|
-
function parseSegmentConfig(value, source) {
|
|
123
|
-
if (!isRecord(value))
|
|
124
|
-
throw new Error(`${source} must be an object`);
|
|
125
|
-
const allowed = new Set(['enabled', 'align', 'style', 'type', 'displayStyle', ...BOOLEAN_SEGMENT_FIELDS, ...NUMBER_SEGMENT_FIELDS]);
|
|
126
|
-
for (const field of Object.keys(value)) {
|
|
127
|
-
if (!allowed.has(field))
|
|
128
|
-
throw new Error(`${source} contains unknown field: ${field}`);
|
|
129
|
-
}
|
|
130
|
-
const config = {
|
|
131
|
-
enabled: value.enabled === undefined ? true : value.enabled,
|
|
132
|
-
};
|
|
133
|
-
if (typeof config.enabled !== 'boolean')
|
|
134
|
-
throw new Error(`${source}.enabled must be a boolean`);
|
|
135
|
-
if (typeof value.align === 'string' && ALIGNMENTS.has(value.align)) {
|
|
136
|
-
config.align = value.align;
|
|
137
|
-
}
|
|
138
|
-
else if (value.align !== undefined)
|
|
139
|
-
throw new Error(`${source}.align is invalid`);
|
|
140
|
-
if (typeof value.style === 'string' && DIRECTORY_STYLES.has(value.style)) {
|
|
141
|
-
config.style = value.style;
|
|
142
|
-
}
|
|
143
|
-
else if (value.style !== undefined)
|
|
144
|
-
throw new Error(`${source}.style is invalid`);
|
|
145
|
-
if (typeof value.type === 'string' && SESSION_TYPES.has(value.type)) {
|
|
146
|
-
config.type = value.type;
|
|
147
|
-
}
|
|
148
|
-
else if (value.type !== undefined)
|
|
149
|
-
throw new Error(`${source}.type is invalid`);
|
|
150
|
-
if (typeof value.displayStyle === 'string' && CONTEXT_STYLES.has(value.displayStyle)) {
|
|
151
|
-
config.displayStyle = value.displayStyle;
|
|
152
|
-
}
|
|
153
|
-
else if (value.displayStyle !== undefined)
|
|
154
|
-
throw new Error(`${source}.displayStyle is invalid`);
|
|
155
|
-
for (const field of BOOLEAN_SEGMENT_FIELDS) {
|
|
156
|
-
if (value[field] !== undefined && typeof value[field] !== 'boolean')
|
|
157
|
-
throw new Error(`${source}.${field} must be a boolean`);
|
|
158
|
-
if (typeof value[field] === 'boolean')
|
|
159
|
-
config[field] = value[field];
|
|
160
|
-
}
|
|
161
|
-
for (const field of NUMBER_SEGMENT_FIELDS) {
|
|
162
|
-
if (value[field] !== undefined && (typeof value[field] !== 'number' || !Number.isFinite(value[field])))
|
|
163
|
-
throw new Error(`${source}.${field} must be a finite number`);
|
|
164
|
-
if (typeof value[field] === 'number')
|
|
165
|
-
config[field] = value[field];
|
|
166
|
-
}
|
|
167
|
-
if (config.periodDays !== undefined && (!Number.isSafeInteger(config.periodDays) || config.periodDays < 1 || config.periodDays > 3_650)) {
|
|
168
|
-
throw new Error(`${source}.periodDays must be an integer from 1 to 3650`);
|
|
169
|
-
}
|
|
170
|
-
return config;
|
|
171
|
-
}
|
|
172
|
-
function findSegment(config, name) {
|
|
173
|
-
for (const line of config.display.lines) {
|
|
174
|
-
const segment = line.segments[name];
|
|
175
|
-
if (segment)
|
|
176
|
-
return segment;
|
|
177
|
-
}
|
|
178
|
-
return undefined;
|
|
179
|
-
}
|
|
180
|
-
function isRecord(value) {
|
|
181
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
182
|
-
}
|
|
183
|
-
function isNodeError(error) {
|
|
184
|
-
return error instanceof Error && 'code' in error;
|
|
185
|
-
}
|
|
186
|
-
function errorMessage(error) {
|
|
187
|
-
return error instanceof Error ? error.message : String(error);
|
|
188
|
-
}
|
|
189
12
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE1E,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;IACpD,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE;QAC3C,eAAe,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;QACxG,cAAc,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;QAC/F,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,8BAA8B;YACtF,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,mCAAmC,EAAE,CAAC;QACpJ,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,oCAAoC;YAC5F,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,gCAAgC,EAAE,CAAC;KAC/I;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SessionsService, UsageService } from '@felan-ai/agent-core';
|
|
2
|
+
import type { PowerlineRuntimeOptions } from './runtime.js';
|
|
3
|
+
export declare function createSavingsUsage(usage: UsageService): NonNullable<PowerlineRuntimeOptions['savingsHost']>;
|
|
4
|
+
export declare function createSessionUsage(sessions: SessionsService): NonNullable<PowerlineRuntimeOptions['additionalSessionUsageHost']>;
|
|
5
|
+
//# sourceMappingURL=core-services.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-services.d.ts","sourceRoot":"","sources":["../src/core-services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAG5D,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAAC,uBAAuB,CAAC,aAAa,CAAC,CAAC,CAS3G;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,WAAW,CAAC,uBAAuB,CAAC,4BAA4B,CAAC,CAAC,CA0ChI"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function createSavingsUsage(usage) {
|
|
2
|
+
return {
|
|
3
|
+
query({ periodDays, signal }) {
|
|
4
|
+
const to = new Date();
|
|
5
|
+
const from = new Date(Date.UTC(to.getUTCFullYear(), to.getUTCMonth(), to.getUTCDate()));
|
|
6
|
+
from.setUTCDate(from.getUTCDate() - (periodDays - 1));
|
|
7
|
+
return usage.querySavings({ from, to, signal });
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function createSessionUsage(sessions) {
|
|
12
|
+
let totals = emptyTotals();
|
|
13
|
+
let active;
|
|
14
|
+
let controller;
|
|
15
|
+
let dirty = false;
|
|
16
|
+
const listeners = new Set();
|
|
17
|
+
const refresh = () => {
|
|
18
|
+
dirty = true;
|
|
19
|
+
if (active)
|
|
20
|
+
return active;
|
|
21
|
+
controller ??= new AbortController();
|
|
22
|
+
const signal = controller.signal;
|
|
23
|
+
active = (async () => {
|
|
24
|
+
do {
|
|
25
|
+
dirty = false;
|
|
26
|
+
const next = emptyTotals();
|
|
27
|
+
let cursor;
|
|
28
|
+
do {
|
|
29
|
+
const page = await sessions.executions({ includeDescendants: true, signal, ...(cursor ? { cursor } : {}) });
|
|
30
|
+
for (const execution of page.items) {
|
|
31
|
+
if (!execution.usage)
|
|
32
|
+
continue;
|
|
33
|
+
const usage = execution.usage;
|
|
34
|
+
next.input += usage.input;
|
|
35
|
+
next.output += usage.output;
|
|
36
|
+
next.cacheRead += usage.cacheRead;
|
|
37
|
+
next.cacheWrite += usage.cacheWrite;
|
|
38
|
+
next.cost += usage.cost;
|
|
39
|
+
}
|
|
40
|
+
cursor = page.nextCursor;
|
|
41
|
+
} while (cursor);
|
|
42
|
+
if (!signal.aborted) {
|
|
43
|
+
totals = next;
|
|
44
|
+
for (const listener of listeners)
|
|
45
|
+
listener();
|
|
46
|
+
}
|
|
47
|
+
} while (dirty && !signal.aborted);
|
|
48
|
+
})().catch(() => { }).finally(() => { active = undefined; });
|
|
49
|
+
return active;
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
getUsage: () => totals,
|
|
53
|
+
settle: async () => { await active; },
|
|
54
|
+
subscribe(listener) {
|
|
55
|
+
listeners.add(listener);
|
|
56
|
+
const unsubscribe = sessions.subscribe(event => { if (event.kind === 'execution')
|
|
57
|
+
void refresh(); });
|
|
58
|
+
void refresh();
|
|
59
|
+
return () => { unsubscribe(); listeners.delete(listener); controller?.abort(); controller = undefined; };
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function emptyTotals() {
|
|
64
|
+
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=core-services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-services.js","sourceRoot":"","sources":["../src/core-services.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,kBAAkB,CAAC,KAAmB;IACpD,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