pi-media-models 0.1.5 → 0.1.6

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": "pi-media-models",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "Provider-neutral multimodal generation tools for Pi Coding Agent",
6
6
  "keywords": [
@@ -30,7 +30,7 @@ export abstract class BaseAdapter implements ProviderAdapter {
30
30
 
31
31
  protected key(request: MediaRequest): string {
32
32
  const configKey = request.providerOptions?.apiKey;
33
- const value = (typeof configKey === "string" ? configKey : undefined) ?? (this.envKey ? this.env[this.envKey] : undefined)
33
+ const value = (typeof configKey === "string" && configKey.trim() ? configKey.trim() : undefined) ?? (this.envKey ? this.env[this.envKey] : undefined)
34
34
  if (!value) throw new MediaError('AUTH', `${this.envKey ?? `${this.id} API key`} is not set in environment or config`, { provider: this.id })
35
35
  return value
36
36
  }
@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url'
3
3
  import { MediaError } from '../errors.js'
4
4
  import { MediaJob } from '../media-job.js'
5
5
  import { BaseAdapter, artifactsOrThrow, makeModel } from './base.js'
6
+ import { expandHomePath } from '../config.js'
6
7
  import type { AdapterContext, AdapterResult, Capability, JobStatus, JsonObject, MediaRequest, ModelDescriptor } from '../types.js'
7
8
  import type { AdapterDependencies } from './base.js'
8
9
 
@@ -164,7 +165,8 @@ export class GoogleMediaAdapter extends BaseAdapter {
164
165
  const options = request.providerOptions;
165
166
  const configuredFile = typeof options?.credentialsFile === "string" ? options.credentialsFile : undefined
166
167
  const rawKeyFilename = configuredFile ?? this.env.VERTEX_CREDENTIALS_FILE ?? this.env.GOOGLE_APPLICATION_CREDENTIALS
167
- const keyFilename = rawKeyFilename?.startsWith('file://') ? fileURLToPath(rawKeyFilename) : rawKeyFilename
168
+ const expandedKeyFile = expandHomePath(rawKeyFilename)
169
+ const keyFilename = expandedKeyFile?.startsWith('file://') ? fileURLToPath(expandedKeyFile) : expandedKeyFile
168
170
  const auth = new GoogleAuth({
169
171
  scopes: ['https://www.googleapis.com/auth/cloud-platform'],
170
172
  ...(keyFilename ? { keyFilename } : {}),
package/src/config.ts CHANGED
@@ -1,9 +1,18 @@
1
1
  import { readFile } from 'node:fs/promises'
2
2
  import { homedir } from 'node:os'
3
- import { join } from 'node:path'
3
+ import { join, resolve } from 'node:path'
4
4
  import { CAPABILITIES, type Capability, type JsonObject } from './types.js'
5
5
  import { MediaError } from './errors.js'
6
6
 
7
+ export function expandHomePath(rawPath: string | undefined): string | undefined {
8
+ if (!rawPath) return undefined
9
+ if (rawPath === '~') return homedir()
10
+ if (rawPath.startsWith('~/') || rawPath.startsWith('~\\')) {
11
+ return join(homedir(), rawPath.slice(2))
12
+ }
13
+ return rawPath
14
+ }
15
+
7
16
  export interface CustomAsyncConfig {
8
17
  idPath: string
9
18
  statusPath: string
@@ -61,8 +70,11 @@ export async function loadMediaConfig(cwd: string, allowProjectConfig: boolean):
61
70
  const globalPath = join(homedir(), '.pi', 'agent', 'media-models.json')
62
71
  const global = await parseFile(globalPath) ?? EMPTY_CONFIG
63
72
  const project = allowProjectConfig ? await parseFile(join(cwd, '.pi', 'media-models.json')) : undefined
73
+ const rawOutputDir = project?.outputDir ?? global.outputDir
74
+ const expandedOutputDir = expandHomePath(rawOutputDir)
75
+ const outputDir = expandedOutputDir ? resolve(cwd, expandedOutputDir) : undefined
64
76
  const merged: MediaConfig = {
65
- outputDir: project?.outputDir ?? global.outputDir,
77
+ outputDir,
66
78
  customProviders: project?.customProviders ?? global.customProviders ?? [],
67
79
  providerOptions: { ...(global.providerOptions ?? {}), ...(project?.providerOptions ?? {}) },
68
80
  }
package/src/router.ts CHANGED
@@ -49,9 +49,15 @@ export class CapabilityRouter {
49
49
  }
50
50
 
51
51
  private isConfigured(adapter: ProviderAdapter): boolean {
52
- if (!adapter.envKey) return true
53
- if (this.env[adapter.envKey]) return true
54
- if (this.providerDefaults[adapter.id]?.apiKey) return true
52
+ if (adapter.id === 'vertex') {
53
+ const vertexOpts = this.providerDefaults['vertex']
54
+ if (typeof vertexOpts?.credentialsFile === 'string' && vertexOpts.credentialsFile.trim()) return true
55
+ if (this.env.GOOGLE_APPLICATION_CREDENTIALS || this.env.VERTEX_CREDENTIALS_FILE) return true
56
+ return false
57
+ }
58
+ const configKey = this.providerDefaults[adapter.id]?.apiKey
59
+ if (typeof configKey === 'string' && configKey.trim()) return true
60
+ if (adapter.envKey && this.env[adapter.envKey]) return true
55
61
  return false
56
62
  }
57
63