@cesarus777/opencode-cgp 0.2.3 → 0.3.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/dist/rpc.js CHANGED
@@ -1,174 +1,33 @@
1
1
  // @bun
2
- // src/rpc.ts
3
- import { Rpc } from "@opencode/plugin/rpc";
4
- var count = {
5
- type: "integer",
6
- minimum: 0,
7
- maximum: Number.MAX_SAFE_INTEGER
8
- };
9
- var text = { type: "string", minLength: 1, maxLength: 512 };
10
- var enumeration = (...values) => ({ type: "string", enum: values });
11
- var object = (properties, required = Object.keys(properties)) => ({
12
- type: "object",
13
- properties,
14
- required,
15
- additionalProperties: false
16
- });
17
- var array = (items, maxItems = 128) => ({
18
- type: "array",
19
- items,
20
- maxItems
21
- });
22
- var measurement = object({
23
- tokens: count,
24
- at: count,
25
- model: text,
26
- requestId: text,
27
- provenance: enumeration("provider-normalized", "serialized-estimate"),
28
- confidence: enumeration("reported", "approximate"),
29
- scope: enumeration("completed-request", "prepared-request")
30
- }, ["tokens", "at", "model", "provenance", "confidence", "scope"]);
31
- var row = object({
32
- sessionId: text,
33
- revision: count,
34
- observedAt: count,
35
- parentId: text,
36
- agent: text,
37
- model: text,
38
- measurement,
39
- limits: object({ context: count, input: count, output: count }, [
40
- "context",
41
- "output"
42
- ]),
43
- capacityTokens: count,
44
- outputReserveTokens: count,
45
- peakTokens: count,
46
- policy: object({
47
- id: text,
48
- configured: object({
49
- type: enumeration("tokens", "ratio", "remaining"),
50
- value: { type: "number", minimum: 0 }
51
- }),
52
- triggerTokens: { type: "number" },
53
- comparison: enumeration(">=", ">"),
54
- reason: enumeration("missing-usage", "model-changed", "invalid-usage", "stale-usage", "missing-model-budget", "incompatible-model-budget", "threshold-crossed", "below-threshold"),
55
- crossed: { type: "boolean" }
56
- }, ["id", "configured", "comparison", "reason", "crossed"]),
57
- compaction: object({
58
- phase: enumeration("idle", "requesting", "accepted", "running", "awaiting-measurement", "blocked", "uncertain"),
59
- count,
60
- armed: { type: "boolean" },
61
- blockedReason: enumeration("session-removed", "compaction-failed", "reclaim-unverifiable", "insufficient-reclaim", "completion-event-timeout", "admission-outcome-unknown", "restart-needs-lifecycle-evidence"),
62
- lastAttempt: count,
63
- lastCompleted: count,
64
- cooldownUntil: count
65
- }, ["phase", "armed"]),
66
- cumulative: object({
67
- input: count,
68
- output: count,
69
- reasoning: count,
70
- cache: object({ read: count, write: count })
71
- }),
72
- cumulativeScope: enumeration("session", "unknown"),
73
- lastObservedActive: { type: "boolean" }
74
- }, [
75
- "sessionId",
76
- "revision",
77
- "observedAt",
78
- "policy",
79
- "compaction",
80
- "cumulativeScope",
81
- "lastObservedActive"
82
- ]);
83
- var batchFields = {
84
- schemaVersion: { const: 1 },
85
- epoch: text,
86
- sequence: count,
87
- generatedAt: count,
88
- health: object({
89
- enabled: { type: "boolean" },
90
- mode: enumeration("observe", "enforce"),
91
- enforcement: enumeration("observing", "available", "suspended", "disabled"),
92
- reasons: array(enumeration("event-stream-gap", "persistence-unavailable", "capacity-exceeded", "model-metadata-unavailable"), 8),
93
- staleMs: count,
94
- maxSessions: count
95
- }),
96
- upserts: array(row),
97
- removed: array(object({
98
- sessionId: text,
99
- revision: count,
100
- reason: enumeration("deleted", "evicted")
101
- }))
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
102
17
  };
103
- var readSchema = object({
104
- schemaVersion: { const: 1 },
105
- sessionIds: { ...array(text), uniqueItems: true }
106
- });
107
- var batchSchema = object(batchFields);
108
- var resultSchema = object({
109
- ...batchFields,
110
- unavailable: array(object({ sessionId: text, reason: enumeration("not-monitored") }))
111
- });
112
- var monitorRpc = Rpc.define({
113
- id: "context-guard.monitor.v1",
114
- methods: { read: { input: readSchema, output: resultSchema } },
115
- events: { changed: { schema: batchSchema } }
116
- });
117
- var nonnegative = { type: "number", minimum: 0 };
118
- var performanceSchema = object({
119
- observedSince: count,
120
- at: count,
121
- sessionCreatedAt: count,
122
- sessionOutputTokens: count,
123
- status: enumeration("waiting", "streaming", "idle", "unavailable"),
124
- partial: { type: "boolean" },
125
- liveTps: nonnegative,
126
- averageModelTps: nonnegative,
127
- averageSessionTps: nonnegative,
128
- ttftMs: nonnegative,
129
- latestRequestTps: nonnegative,
130
- requestId: text,
131
- requestAgent: text,
132
- requestModel: text,
133
- requestOutputTokens: count,
134
- requestStartedAt: count,
135
- firstOutputAt: count,
136
- streamEndedAt: count,
137
- estimatedOutputTokens: nonnegative,
138
- modelOutputTokens: nonnegative,
139
- modelDurationMs: nonnegative,
140
- completedRequests: count,
141
- tokenSource: enumeration("estimated", "reported", "unavailable")
142
- }, [
143
- "sessionCreatedAt",
144
- "observedSince",
145
- "at",
146
- "status",
147
- "partial",
148
- "estimatedOutputTokens",
149
- "modelOutputTokens",
150
- "modelDurationMs",
151
- "completedRequests",
152
- "tokenSource"
153
- ]);
154
- var performanceRow = {
155
- ...row,
156
- properties: { ...row.properties, performance: performanceSchema }
18
+ var __export = (target, all) => {
19
+ for (var name in all)
20
+ __defProp(target, name, {
21
+ get: all[name],
22
+ enumerable: true,
23
+ configurable: true,
24
+ set: (newValue) => all[name] = () => newValue
25
+ });
157
26
  };
158
- var performanceBatchSchema = object({
159
- ...batchFields,
160
- upserts: array(performanceRow)
161
- });
162
- var performanceResultSchema = object({
163
- ...batchFields,
164
- upserts: array(performanceRow),
165
- unavailable: resultSchema.properties.unavailable ?? {}
166
- });
167
- var performanceRpc = Rpc.define({
168
- id: "context-guard.monitor.v2",
169
- methods: { read: { input: readSchema, output: performanceResultSchema } },
170
- events: { changed: { schema: performanceBatchSchema } }
171
- });
27
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
28
+
29
+ // src/rpc.ts
30
+ import { Rpc } from "@opencode/plugin/rpc";
172
31
  function isPerformanceBatch(value) {
173
32
  return valid(value, performanceBatchSchema) && uniqueRows(value);
174
33
  }
@@ -178,84 +37,6 @@ function isPerformanceResult(value) {
178
37
  function isPerformanceSnapshot(value) {
179
38
  return valid(value, performanceSchema);
180
39
  }
181
- var chartPointSchema = object({
182
- time: count,
183
- agent: text,
184
- model: text,
185
- breakBefore: { type: "boolean" },
186
- partial: { type: "boolean" },
187
- liveTps: nonnegative,
188
- averageModelTps: nonnegative,
189
- averageSessionTps: nonnegative,
190
- sessionOutputTokens: count
191
- }, ["time", "breakBefore", "partial"]);
192
- var chartRequestSchema = object({
193
- time: count,
194
- requestId: text,
195
- started: count,
196
- agent: text,
197
- model: text,
198
- ttftMs: nonnegative,
199
- outputTokens: count,
200
- durationMs: nonnegative,
201
- tps: nonnegative,
202
- partial: { type: "boolean" }
203
- }, ["time", "requestId", "started", "partial"]);
204
- var historyReadSchema = object({
205
- schemaVersion: { const: 1 },
206
- sessionId: text,
207
- from: count,
208
- to: count,
209
- maxPoints: { type: "integer", minimum: 16, maximum: 500 }
210
- });
211
- var historyResultSchema = object({
212
- schemaVersion: { const: 1 },
213
- generatedAt: count,
214
- enabled: { type: "boolean" },
215
- truncated: { type: "boolean" },
216
- metadata: object({
217
- schema: { const: 1 },
218
- retainedFrom: count,
219
- retainedBytes: count,
220
- skippedBytes: count,
221
- malformedRecords: count,
222
- completeness: enumeration("bounded-retention")
223
- }, [
224
- "schema",
225
- "retainedBytes",
226
- "skippedBytes",
227
- "malformedRecords",
228
- "completeness"
229
- ]),
230
- data: object({
231
- schema: { const: 1 },
232
- omittedSessions: count,
233
- omittedGaps: count,
234
- maxPoints: count,
235
- gaps: array(object({ time: count, sessionId: text, reason: text }), 128),
236
- series: array(object({
237
- sessionId: text,
238
- parentId: text,
239
- agents: array(text, 1024),
240
- models: array(text, 1024),
241
- points: array(chartPointSchema, 500),
242
- requests: array(chartRequestSchema, 500),
243
- originalPoints: count
244
- }, [
245
- "sessionId",
246
- "agents",
247
- "models",
248
- "points",
249
- "requests",
250
- "originalPoints"
251
- ]), 1)
252
- }, ["schema", "omittedSessions", "maxPoints", "gaps", "series"])
253
- });
254
- var historyRpc = Rpc.define({
255
- id: "context-guard.history.v1",
256
- methods: { read: { input: historyReadSchema, output: historyResultSchema } },
257
- events: {}
258
- });
259
40
  function isHistoryRead(value) {
260
41
  return valid(value, historyReadSchema) && record(value) && typeof value.from === "number" && typeof value.to === "number" && value.from <= value.to && value.to - value.from <= 7 * 86400000;
261
42
  }
@@ -310,6 +91,254 @@ function uniqueRows(value) {
310
91
  const ids = [...value.upserts, ...value.removed].map((v) => record(v) ? v.sessionId : undefined);
311
92
  return ids.length <= 128 && new Set(ids).size === ids.length;
312
93
  }
94
+ var count, text, enumeration = (...values) => ({ type: "string", enum: values }), object = (properties, required = Object.keys(properties)) => ({
95
+ type: "object",
96
+ properties,
97
+ required,
98
+ additionalProperties: false
99
+ }), array = (items, maxItems = 128) => ({
100
+ type: "array",
101
+ items,
102
+ maxItems
103
+ }), measurement, row, batchFields, readSchema, batchSchema, resultSchema, monitorRpc, nonnegative, performanceSchema, performanceRow, performanceBatchSchema, performanceResultSchema, performanceRpc, chartPointSchema, chartRequestSchema, historyReadSchema, historyResultSchema, historyRpc;
104
+ var init_rpc = __esm(() => {
105
+ count = {
106
+ type: "integer",
107
+ minimum: 0,
108
+ maximum: Number.MAX_SAFE_INTEGER
109
+ };
110
+ text = { type: "string", minLength: 1, maxLength: 512 };
111
+ measurement = object({
112
+ tokens: count,
113
+ at: count,
114
+ model: text,
115
+ requestId: text,
116
+ provenance: enumeration("provider-normalized", "serialized-estimate"),
117
+ confidence: enumeration("reported", "approximate"),
118
+ scope: enumeration("completed-request", "prepared-request")
119
+ }, ["tokens", "at", "model", "provenance", "confidence", "scope"]);
120
+ row = object({
121
+ sessionId: text,
122
+ revision: count,
123
+ observedAt: count,
124
+ parentId: text,
125
+ agent: text,
126
+ model: text,
127
+ measurement,
128
+ limits: object({ context: count, input: count, output: count }, [
129
+ "context",
130
+ "output"
131
+ ]),
132
+ capacityTokens: count,
133
+ outputReserveTokens: count,
134
+ peakTokens: count,
135
+ policy: object({
136
+ id: text,
137
+ configured: object({
138
+ type: enumeration("tokens", "ratio", "remaining"),
139
+ value: { type: "number", minimum: 0 }
140
+ }),
141
+ triggerTokens: { type: "number" },
142
+ comparison: enumeration(">=", ">"),
143
+ reason: enumeration("missing-usage", "model-changed", "invalid-usage", "stale-usage", "missing-model-budget", "incompatible-model-budget", "threshold-crossed", "below-threshold"),
144
+ crossed: { type: "boolean" }
145
+ }, ["id", "configured", "comparison", "reason", "crossed"]),
146
+ compaction: object({
147
+ phase: enumeration("idle", "requesting", "accepted", "running", "awaiting-measurement", "blocked", "uncertain"),
148
+ count,
149
+ armed: { type: "boolean" },
150
+ blockedReason: enumeration("session-removed", "compaction-failed", "reclaim-unverifiable", "insufficient-reclaim", "completion-event-timeout", "admission-outcome-unknown", "restart-needs-lifecycle-evidence"),
151
+ lastAttempt: count,
152
+ lastCompleted: count,
153
+ cooldownUntil: count
154
+ }, ["phase", "armed"]),
155
+ cumulative: object({
156
+ input: count,
157
+ output: count,
158
+ reasoning: count,
159
+ cache: object({ read: count, write: count })
160
+ }),
161
+ cumulativeScope: enumeration("session", "unknown"),
162
+ lastObservedActive: { type: "boolean" }
163
+ }, [
164
+ "sessionId",
165
+ "revision",
166
+ "observedAt",
167
+ "policy",
168
+ "compaction",
169
+ "cumulativeScope",
170
+ "lastObservedActive"
171
+ ]);
172
+ batchFields = {
173
+ schemaVersion: { const: 1 },
174
+ epoch: text,
175
+ sequence: count,
176
+ generatedAt: count,
177
+ health: object({
178
+ enabled: { type: "boolean" },
179
+ mode: enumeration("observe", "enforce"),
180
+ enforcement: enumeration("observing", "available", "suspended", "disabled"),
181
+ reasons: array(enumeration("event-stream-gap", "persistence-unavailable", "capacity-exceeded", "model-metadata-unavailable"), 8),
182
+ staleMs: count,
183
+ maxSessions: count
184
+ }),
185
+ upserts: array(row),
186
+ removed: array(object({
187
+ sessionId: text,
188
+ revision: count,
189
+ reason: enumeration("deleted", "evicted")
190
+ }))
191
+ };
192
+ readSchema = object({
193
+ schemaVersion: { const: 1 },
194
+ sessionIds: { ...array(text), uniqueItems: true }
195
+ });
196
+ batchSchema = object(batchFields);
197
+ resultSchema = object({
198
+ ...batchFields,
199
+ unavailable: array(object({ sessionId: text, reason: enumeration("not-monitored") }))
200
+ });
201
+ monitorRpc = Rpc.define({
202
+ id: "context-guard.monitor.v1",
203
+ methods: { read: { input: readSchema, output: resultSchema } },
204
+ events: { changed: { schema: batchSchema } }
205
+ });
206
+ nonnegative = { type: "number", minimum: 0 };
207
+ performanceSchema = object({
208
+ observedSince: count,
209
+ at: count,
210
+ sessionCreatedAt: count,
211
+ sessionOutputTokens: count,
212
+ status: enumeration("waiting", "streaming", "idle", "unavailable"),
213
+ partial: { type: "boolean" },
214
+ liveTps: nonnegative,
215
+ averageModelTps: nonnegative,
216
+ averageSessionTps: nonnegative,
217
+ ttftMs: nonnegative,
218
+ latestRequestTps: nonnegative,
219
+ requestId: text,
220
+ requestAgent: text,
221
+ requestModel: text,
222
+ requestOutputTokens: count,
223
+ requestStartedAt: count,
224
+ firstOutputAt: count,
225
+ streamEndedAt: count,
226
+ estimatedOutputTokens: nonnegative,
227
+ modelOutputTokens: nonnegative,
228
+ modelDurationMs: nonnegative,
229
+ completedRequests: count,
230
+ tokenSource: enumeration("estimated", "reported", "unavailable")
231
+ }, [
232
+ "sessionCreatedAt",
233
+ "observedSince",
234
+ "at",
235
+ "status",
236
+ "partial",
237
+ "estimatedOutputTokens",
238
+ "modelOutputTokens",
239
+ "modelDurationMs",
240
+ "completedRequests",
241
+ "tokenSource"
242
+ ]);
243
+ performanceRow = {
244
+ ...row,
245
+ properties: { ...row.properties, performance: performanceSchema }
246
+ };
247
+ performanceBatchSchema = object({
248
+ ...batchFields,
249
+ upserts: array(performanceRow)
250
+ });
251
+ performanceResultSchema = object({
252
+ ...batchFields,
253
+ upserts: array(performanceRow),
254
+ unavailable: resultSchema.properties.unavailable ?? {}
255
+ });
256
+ performanceRpc = Rpc.define({
257
+ id: "context-guard.monitor.v2",
258
+ methods: { read: { input: readSchema, output: performanceResultSchema } },
259
+ events: { changed: { schema: performanceBatchSchema } }
260
+ });
261
+ chartPointSchema = object({
262
+ time: count,
263
+ agent: text,
264
+ model: text,
265
+ breakBefore: { type: "boolean" },
266
+ partial: { type: "boolean" },
267
+ liveTps: nonnegative,
268
+ averageModelTps: nonnegative,
269
+ averageSessionTps: nonnegative,
270
+ sessionOutputTokens: count
271
+ }, ["time", "breakBefore", "partial"]);
272
+ chartRequestSchema = object({
273
+ time: count,
274
+ requestId: text,
275
+ started: count,
276
+ agent: text,
277
+ model: text,
278
+ ttftMs: nonnegative,
279
+ outputTokens: count,
280
+ durationMs: nonnegative,
281
+ tps: nonnegative,
282
+ partial: { type: "boolean" }
283
+ }, ["time", "requestId", "started", "partial"]);
284
+ historyReadSchema = object({
285
+ schemaVersion: { const: 1 },
286
+ sessionId: text,
287
+ from: count,
288
+ to: count,
289
+ maxPoints: { type: "integer", minimum: 16, maximum: 500 }
290
+ });
291
+ historyResultSchema = object({
292
+ schemaVersion: { const: 1 },
293
+ generatedAt: count,
294
+ enabled: { type: "boolean" },
295
+ truncated: { type: "boolean" },
296
+ metadata: object({
297
+ schema: { const: 1 },
298
+ retainedFrom: count,
299
+ retainedBytes: count,
300
+ skippedBytes: count,
301
+ malformedRecords: count,
302
+ completeness: enumeration("bounded-retention")
303
+ }, [
304
+ "schema",
305
+ "retainedBytes",
306
+ "skippedBytes",
307
+ "malformedRecords",
308
+ "completeness"
309
+ ]),
310
+ data: object({
311
+ schema: { const: 1 },
312
+ omittedSessions: count,
313
+ omittedGaps: count,
314
+ maxPoints: count,
315
+ gaps: array(object({ time: count, sessionId: text, reason: text }), 128),
316
+ series: array(object({
317
+ sessionId: text,
318
+ parentId: text,
319
+ agents: array(text, 1024),
320
+ models: array(text, 1024),
321
+ points: array(chartPointSchema, 500),
322
+ requests: array(chartRequestSchema, 500),
323
+ originalPoints: count
324
+ }, [
325
+ "sessionId",
326
+ "agents",
327
+ "models",
328
+ "points",
329
+ "requests",
330
+ "originalPoints"
331
+ ]), 1)
332
+ }, ["schema", "omittedSessions", "maxPoints", "gaps", "series"])
333
+ });
334
+ historyRpc = Rpc.define({
335
+ id: "context-guard.history.v1",
336
+ methods: { read: { input: historyReadSchema, output: historyResultSchema } },
337
+ events: {}
338
+ });
339
+ });
340
+ init_rpc();
341
+
313
342
  export {
314
343
  resultSchema,
315
344
  readSchema,