@anionex/dsh-vision-toolkit 0.1.43 → 0.1.44

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/src/exposure.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  import type { Agent } from '@deepseek-ai/dsh-agent'
10
10
  import type { ContentBlock } from '@deepseek-ai/dsh-llm'
11
11
  import type { Session } from '@deepseek-ai/dsh-session'
12
+ import type { SessionEvent } from '@deepseek-ai/dsh-session/types'
12
13
  import { defineTool, type ToolDefinition } from '@deepseek-ai/dsh-tools'
13
14
  import type { Context } from '@deepseek-ai/cordis'
14
15
  import { VISION_SKILLS_CONTENT, VISION_SKILLS_NAME } from './skill.ts'
@@ -78,12 +79,49 @@ function isBundledSkillResult(value: unknown): boolean {
78
79
  && isBundledSkillContent(value.content)
79
80
  }
80
81
 
82
+ /** Event names for one settled programmatic (PTC) Tool dispatch. */
83
+ const PTC_DISPATCH_EVENT_TYPES: readonly string[] = ['tool/ptc-dispatch', 'tool/code-dispatch']
84
+
85
+ /**
86
+ * Whether one PTC dispatch event records a successful load of the bundled
87
+ * Skill. The event is `tool/code-dispatch` through 0.1.2 and `tool/ptc-dispatch`
88
+ * from 0.1.5, so the name is compared outside the typed union and the payload is
89
+ * read structurally instead of narrowing on the installed host's literal.
90
+ * @param event - one durable Session event.
91
+ * @returns true when this dispatch ran the bundled Skill and returned its content.
92
+ */
93
+ function isBundledSkillPtcDispatch(event: SessionEvent): boolean {
94
+ const type: string = event.type
95
+ if (!PTC_DISPATCH_EVENT_TYPES.includes(type)) return false
96
+ const data = (event as { data?: unknown }).data
97
+ return isRecord(data)
98
+ && data.name === 'skill'
99
+ && data.isError === false
100
+ && isVisionSkillArguments(data.arguments)
101
+ && containsBundledSkillContent(Array.isArray(data.content) ? data.content : [])
102
+ }
103
+
104
+ /**
105
+ * Read a Session's durable event log across both published accessors: 0.1.1 and
106
+ * earlier expose the `events` getter, while 0.1.2 replaced it with
107
+ * `snapshotEvents()` and dropped the property from the type. Probing
108
+ * structurally keeps every release line this package declares working at
109
+ * runtime and still compiles against the installed 0.1.5 typings.
110
+ * @param session - the Session whose durable history is inspected.
111
+ * @returns the event log in log order, empty when neither accessor is present.
112
+ */
113
+ function sessionEvents(session: Session): readonly SessionEvent[] {
114
+ const adapter = session as unknown as {
115
+ snapshotEvents?: () => readonly SessionEvent[]
116
+ events?: readonly SessionEvent[]
117
+ }
118
+ return typeof adapter.snapshotEvents === 'function' ? adapter.snapshotEvents() : adapter.events ?? []
119
+ }
120
+
81
121
  /** Whether durable history proves that this Session loaded the bundled Skill. */
82
122
  function hasLoadedVisionSkill(session: Session): boolean {
83
123
  const nativeCalls = new Set<string>()
84
- const events = typeof (session as any).snapshotEvents === 'function'
85
- ? (session as any).snapshotEvents()
86
- : session.events ?? []
124
+ const events = sessionEvents(session)
87
125
  for (const event of events) {
88
126
  if (event.type === 'user/message') {
89
127
  const source = event.data.source
@@ -106,11 +144,7 @@ function hasLoadedVisionSkill(session: Session): boolean {
106
144
  && containsBundledSkillContent(block.content)) return true
107
145
  continue
108
146
  }
109
- if (event.type === 'tool/code-dispatch'
110
- && event.data.name === 'skill'
111
- && event.data.isError === false
112
- && isVisionSkillArguments(event.data.arguments)
113
- && containsBundledSkillContent(event.data.content)) return true
147
+ if (isBundledSkillPtcDispatch(event)) return true
114
148
  }
115
149
  return false
116
150
  }
package/src/tools.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import type { ContentBlock } from '@deepseek-ai/dsh-llm'
10
- import { defineTool, type JsonValue, type ToolRunContext, type ValueSchemaSpec } from '@deepseek-ai/dsh-tools'
10
+ import { defineTool, type ToolRunContext, type ValueSchemaSpec } from '@deepseek-ai/dsh-tools'
11
11
  import {
12
12
  VisionToolkitRuntime,
13
13
  type CropRequest,
@@ -23,6 +23,17 @@ import {
23
23
  } from './runtime.ts'
24
24
  import { platformTempDirectory } from './paths.ts'
25
25
 
26
+ /**
27
+ * A value that round-trips through JSON without loss, as the host transports it
28
+ * through `presentationMeta`. DSH 0.1.2 stopped exporting this type from
29
+ * `@deepseek-ai/dsh-tools`, and 0.1.5 keeps it in `@deepseek-ai/dsh-util-values`,
30
+ * a package that does not exist before 0.1.2-alpha.2, so no single specifier
31
+ * covers every release line this package declares. Both homes declare the
32
+ * identical structural union, so redeclaring it here costs nothing and lets old
33
+ * and new hosts compile against the same contract.
34
+ */
35
+ export type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue }
36
+
26
37
  const renderJson = (_args: unknown, value: unknown): ContentBlock[] => [{
27
38
  type: 'text',
28
39
  text: JSON.stringify(value, null, 2),