@cfbender/cesium 0.7.1 → 0.7.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfbender/cesium",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Beautiful self-contained HTML artifacts from your opencode agent.",
5
5
  "keywords": [
6
6
  "agent",
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ import { createStyleguideTool } from "./tools/styleguide.ts";
12
12
  import { createCritiqueTool } from "./tools/critique.ts";
13
13
  import { createStopTool } from "./tools/stop.ts";
14
14
  import { generateBlockFieldReference } from "./prompt/field-reference.ts";
15
+ import { recordSessionModel } from "./session-model.ts";
15
16
 
16
17
  const rawFragment = await readFile(
17
18
  join(dirname(fileURLToPath(import.meta.url)), "prompt/system-fragment.md"),
@@ -37,6 +38,11 @@ export const CesiumPlugin: Plugin = async (ctx): Promise<Hooks> => {
37
38
  "experimental.chat.system.transform": async (_input, output) => {
38
39
  output.system.push(PROMPT_FRAGMENT);
39
40
  },
41
+ "chat.params": async (input, _output) => {
42
+ // Record the model resolved for this session so tool handlers can stamp
43
+ // it onto generated artifacts. Latest call wins (model can change mid-session).
44
+ recordSessionModel(input.sessionID, input.model.providerID, input.model.id);
45
+ },
40
46
  };
41
47
  };
42
48
 
@@ -0,0 +1,23 @@
1
+ // Tracks the model in use per opencode session.
2
+ //
3
+ // opencode's `chat.params` hook fires before each LLM request with the resolved
4
+ // Model. We record `providerID/id` keyed by sessionID so that tool handlers
5
+ // (publish/ask/annotate) can stamp the generating model onto every artifact's
6
+ // metadata footer. The map is process-local and resets on plugin reload.
7
+
8
+ const sessionModels = new Map<string, string>();
9
+
10
+ export function recordSessionModel(sessionID: string, providerID: string, modelID: string): void {
11
+ if (!sessionID || !providerID || !modelID) return;
12
+ sessionModels.set(sessionID, `${providerID}/${modelID}`);
13
+ }
14
+
15
+ export function getSessionModel(sessionID: string | undefined | null): string | null {
16
+ if (!sessionID) return null;
17
+ return sessionModels.get(sessionID) ?? null;
18
+ }
19
+
20
+ /** Test-only: clear all recorded session models. */
21
+ export function resetSessionModels(): void {
22
+ sessionModels.clear();
23
+ }
@@ -26,6 +26,7 @@ import {
26
26
  type LifecycleConfig,
27
27
  } from "../server/lifecycle.ts";
28
28
  import { buildTerminalSummary, resolveDisplayHost } from "./publish.ts";
29
+ import { getSessionModel } from "../session-model.ts";
29
30
 
30
31
  export interface AnnotateToolOverrides {
31
32
  loadConfig?: () => CesiumConfig;
@@ -84,7 +85,7 @@ export function createAnnotateTool(
84
85
  tags: tool.schema.array(tool.schema.string()).optional(),
85
86
  expiresAt: tool.schema.string().optional(),
86
87
  },
87
- async execute(args, _context) {
88
+ async execute(args, context) {
88
89
  // 1. Validate top-level input shape
89
90
  const validation = validateAnnotateInput(args);
90
91
  if (!validation.ok) {
@@ -181,8 +182,8 @@ export function createAnnotateTool(
181
182
  summary: input.summary ?? null,
182
183
  tags: input.tags ?? [],
183
184
  createdAt: createdAt.toISOString(),
184
- model: null,
185
- sessionId: null,
185
+ model: getSessionModel(context.sessionID),
186
+ sessionId: context.sessionID ?? null,
186
187
  projectSlug: identity.slug,
187
188
  projectName: identity.name,
188
189
  cwd: ctx.directory,
package/src/tools/ask.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  type LifecycleConfig,
26
26
  } from "../server/lifecycle.ts";
27
27
  import { buildTerminalSummary, resolveDisplayHost } from "./publish.ts";
28
+ import { getSessionModel } from "../session-model.ts";
28
29
 
29
30
  export interface AskToolOverrides {
30
31
  loadConfig?: () => CesiumConfig;
@@ -106,7 +107,7 @@ export function createAskTool(
106
107
  expiresAt: tool.schema.string().optional(),
107
108
  requireAll: tool.schema.boolean().optional(),
108
109
  },
109
- async execute(args, _context) {
110
+ async execute(args, context) {
110
111
  // 1. Validate input
111
112
  const validation = validateAskInput(args);
112
113
  if (!validation.ok) {
@@ -193,8 +194,8 @@ export function createAskTool(
193
194
  summary: input.summary ?? null,
194
195
  tags: input.tags ?? [],
195
196
  createdAt: createdAt.toISOString(),
196
- model: null,
197
- sessionId: null,
197
+ model: getSessionModel(context.sessionID),
198
+ sessionId: context.sessionID ?? null,
198
199
  projectSlug: identity.slug,
199
200
  projectName: identity.name,
200
201
  cwd: ctx.directory,
@@ -31,6 +31,7 @@ import {
31
31
  type RunningInfo,
32
32
  type LifecycleConfig,
33
33
  } from "../server/lifecycle.ts";
34
+ import { getSessionModel } from "../session-model.ts";
34
35
 
35
36
  export interface PublishToolOverrides {
36
37
  loadConfig?: () => CesiumConfig;
@@ -107,7 +108,7 @@ export function createPublishTool(
107
108
  tags: tool.schema.array(tool.schema.string()).optional(),
108
109
  supersedes: tool.schema.string().optional(),
109
110
  },
110
- async execute(args, _context) {
111
+ async execute(args, context) {
111
112
  // 1. Validate input
112
113
  const validation = validatePublishInput(args);
113
114
  if (!validation.ok) {
@@ -190,8 +191,8 @@ export function createPublishTool(
190
191
  summary: input.summary ?? null,
191
192
  tags: input.tags ?? [],
192
193
  createdAt: createdAt.toISOString(),
193
- model: null,
194
- sessionId: null,
194
+ model: getSessionModel(context.sessionID),
195
+ sessionId: context.sessionID ?? null,
195
196
  projectSlug: identity.slug,
196
197
  projectName: identity.name,
197
198
  cwd: ctx.directory,