@pikku/inspector 0.12.4 → 0.12.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.
@@ -1,10 +1,3 @@
1
- import * as ts from 'typescript'
2
- import {
3
- getPropertyValue,
4
- getArrayPropertyValue,
5
- } from '../utils/get-property-value.js'
6
- import type { AddWiring } from '../types.js'
7
- import { ErrorCode } from '../error-codes.js'
8
1
  import { createAddKeyedWiring } from './add-keyed-wiring.js'
9
2
 
10
3
  export const addSecret = createAddKeyedWiring({
@@ -14,127 +7,3 @@ export const addSecret = createAddKeyedWiring({
14
7
  schemaPrefix: 'SecretSchema',
15
8
  getState: (state) => state.secrets,
16
9
  })
17
-
18
- export const addOAuth2Credential: AddWiring = (
19
- logger,
20
- node,
21
- _checker,
22
- state,
23
- _options
24
- ) => {
25
- if (!ts.isCallExpression(node)) {
26
- return
27
- }
28
-
29
- const args = node.arguments
30
- const firstArg = args[0]
31
- const expression = node.expression
32
-
33
- if (
34
- !ts.isIdentifier(expression) ||
35
- expression.text !== 'wireOAuth2Credential'
36
- ) {
37
- return
38
- }
39
-
40
- if (!firstArg) {
41
- return
42
- }
43
-
44
- if (ts.isObjectLiteralExpression(firstArg)) {
45
- const obj = firstArg
46
-
47
- const nameValue = getPropertyValue(obj, 'name') as string | null
48
- const displayNameValue = getPropertyValue(obj, 'displayName') as
49
- | string
50
- | null
51
- const descriptionValue = getPropertyValue(obj, 'description') as
52
- | string
53
- | null
54
- const secretIdValue = getPropertyValue(obj, 'secretId') as string | null
55
- const tokenSecretIdValue = getPropertyValue(obj, 'tokenSecretId') as
56
- | string
57
- | null
58
- const authorizationUrlValue = getPropertyValue(obj, 'authorizationUrl') as
59
- | string
60
- | null
61
- const tokenUrlValue = getPropertyValue(obj, 'tokenUrl') as string | null
62
- const scopesValue = getArrayPropertyValue(obj, 'scopes')
63
- const pkceValue = getPropertyValue(obj, 'pkce') as boolean | null
64
-
65
- if (!nameValue) {
66
- logger.critical(
67
- ErrorCode.MISSING_NAME,
68
- "OAuth2 Credential is missing the required 'name' property."
69
- )
70
- return
71
- }
72
-
73
- if (!displayNameValue) {
74
- logger.critical(
75
- ErrorCode.MISSING_NAME,
76
- `OAuth2 Credential '${nameValue}' is missing the required 'displayName' property.`
77
- )
78
- return
79
- }
80
-
81
- if (!secretIdValue) {
82
- logger.critical(
83
- ErrorCode.MISSING_NAME,
84
- `OAuth2 Credential '${nameValue}' is missing the required 'secretId' property.`
85
- )
86
- return
87
- }
88
-
89
- if (!tokenSecretIdValue) {
90
- logger.critical(
91
- ErrorCode.MISSING_NAME,
92
- `OAuth2 Credential '${nameValue}' is missing the required 'tokenSecretId' property.`
93
- )
94
- return
95
- }
96
-
97
- if (!authorizationUrlValue) {
98
- logger.critical(
99
- ErrorCode.MISSING_NAME,
100
- `OAuth2 Credential '${nameValue}' is missing the required 'authorizationUrl' property.`
101
- )
102
- return
103
- }
104
-
105
- if (!tokenUrlValue) {
106
- logger.critical(
107
- ErrorCode.MISSING_NAME,
108
- `OAuth2 Credential '${nameValue}' is missing the required 'tokenUrl' property.`
109
- )
110
- return
111
- }
112
-
113
- if (!scopesValue || scopesValue.length === 0) {
114
- logger.critical(
115
- ErrorCode.MISSING_NAME,
116
- `OAuth2 Credential '${nameValue}' is missing the required 'scopes' property.`
117
- )
118
- return
119
- }
120
-
121
- const sourceFile = node.getSourceFile().fileName
122
-
123
- state.secrets.files.add(sourceFile)
124
-
125
- state.secrets.definitions.push({
126
- name: nameValue,
127
- displayName: displayNameValue,
128
- description: descriptionValue || undefined,
129
- secretId: secretIdValue,
130
- oauth2: {
131
- tokenSecretId: tokenSecretIdValue,
132
- authorizationUrl: authorizationUrlValue,
133
- tokenUrl: tokenUrlValue,
134
- scopes: scopesValue,
135
- pkce: pkceValue || undefined,
136
- },
137
- sourceFile,
138
- })
139
- }
140
- }
@@ -43,6 +43,7 @@ export function addWireAddon(
43
43
  let mcp: boolean | undefined
44
44
  let secretOverrides: Record<string, string> | undefined
45
45
  let variableOverrides: Record<string, string> | undefined
46
+ let credentialOverrides: Record<string, string> | undefined
46
47
 
47
48
  for (const prop of firstArg.properties) {
48
49
  if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name)) continue
@@ -70,6 +71,11 @@ export function addWireAddon(
70
71
  ts.isObjectLiteralExpression(prop.initializer)
71
72
  ) {
72
73
  variableOverrides = parseStringRecord(prop.initializer)
74
+ } else if (
75
+ key === 'credentialOverrides' &&
76
+ ts.isObjectLiteralExpression(prop.initializer)
77
+ ) {
78
+ credentialOverrides = parseStringRecord(prop.initializer)
73
79
  }
74
80
  }
75
81
 
@@ -82,6 +88,7 @@ export function addWireAddon(
82
88
  mcp,
83
89
  secretOverrides,
84
90
  variableOverrides,
91
+ credentialOverrides,
85
92
  })
86
93
  state.rpc.usedAddons.add(name)
87
94
  state.rpc.wireAddonFiles.add(node.getSourceFile().fileName)
package/src/inspector.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  validateAgentOverrides,
16
16
  validateSecretOverrides,
17
17
  validateVariableOverrides,
18
+ validateCredentialOverrides,
18
19
  computeResolvedIOTypes,
19
20
  computeMiddlewareGroupsMeta,
20
21
  computePermissionsGroupsMeta,
@@ -148,6 +149,10 @@ export function getInitialInspectorState(rootDir: string): InspectorState {
148
149
  definitions: [],
149
150
  files: new Set(),
150
151
  },
152
+ credentials: {
153
+ definitions: [],
154
+ files: new Set(),
155
+ },
151
156
  variables: {
152
157
  definitions: [],
153
158
  files: new Set(),
@@ -352,6 +357,7 @@ export const inspect = async (
352
357
  validateAgentOverrides(logger, state, options.modelConfig)
353
358
  validateSecretOverrides(logger, state)
354
359
  validateVariableOverrides(logger, state)
360
+ validateCredentialOverrides(logger, state)
355
361
  }
356
362
 
357
363
  state.program = program
package/src/types.ts CHANGED
@@ -15,6 +15,7 @@ import type { AIAgentMeta } from '@pikku/core/ai-agent'
15
15
  import type { CLIMeta } from '@pikku/core/cli'
16
16
  import type { NodesMeta } from '@pikku/core/node'
17
17
  import type { SecretDefinitions } from '@pikku/core/secret'
18
+ import type { CredentialDefinitions } from '@pikku/core/credential'
18
19
  import type { VariableDefinitions } from '@pikku/core/variable'
19
20
  import type { TypesMap } from './types-map.js'
20
21
  import type {
@@ -353,6 +354,7 @@ export interface InspectorState {
353
354
  mcp?: boolean
354
355
  secretOverrides?: Record<string, string>
355
356
  variableOverrides?: Record<string, string>
357
+ credentialOverrides?: Record<string, string>
356
358
  }
357
359
  >
358
360
  wireAddonFiles: Set<string>
@@ -379,6 +381,10 @@ export interface InspectorState {
379
381
  definitions: SecretDefinitions
380
382
  files: Set<string>
381
383
  }
384
+ credentials: {
385
+ definitions: CredentialDefinitions
386
+ files: Set<string>
387
+ }
382
388
  variables: {
383
389
  definitions: VariableDefinitions
384
390
  files: Set<string>
@@ -247,6 +247,32 @@ export function validateSecretOverrides(
247
247
  }
248
248
  }
249
249
 
250
+ export function validateCredentialOverrides(
251
+ logger: InspectorLogger,
252
+ state: InspectorState | Omit<InspectorState, 'typesLookup'>
253
+ ): void {
254
+ const { wireAddonDeclarations } = state.rpc
255
+ if (!wireAddonDeclarations || wireAddonDeclarations.size === 0) return
256
+
257
+ const credentialNames = new Set(
258
+ state.credentials?.definitions.map((d) => d.name) ?? []
259
+ )
260
+
261
+ for (const [namespace, addonDecl] of wireAddonDeclarations.entries()) {
262
+ if (!addonDecl.credentialOverrides) continue
263
+
264
+ for (const credentialKey of Object.keys(addonDecl.credentialOverrides)) {
265
+ if (!credentialNames.has(credentialKey)) {
266
+ const availableCredentials = Array.from(credentialNames)
267
+ logger.critical(
268
+ ErrorCode.INVALID_VALUE,
269
+ `Credential override '${credentialKey}' in addon '${namespace}' (${addonDecl.package}) does not exist. Available credentials: ${availableCredentials.join(', ') || 'none'}`
270
+ )
271
+ }
272
+ }
273
+ }
274
+ }
275
+
250
276
  export function validateVariableOverrides(
251
277
  logger: InspectorLogger,
252
278
  state: InspectorState | Omit<InspectorState, 'typesLookup'>
@@ -19,6 +19,7 @@ export const resolveAddonName = (
19
19
  rpcEndpoint?: string
20
20
  secretOverrides?: Record<string, string>
21
21
  variableOverrides?: Record<string, string>
22
+ credentialOverrides?: Record<string, string>
22
23
  }
23
24
  >
24
25
  ): string | null => {
@@ -156,6 +156,7 @@ export interface SerializableInspectorState {
156
156
  rpcEndpoint?: string
157
157
  secretOverrides?: Record<string, string>
158
158
  variableOverrides?: Record<string, string>
159
+ credentialOverrides?: Record<string, string>
159
160
  },
160
161
  ]
161
162
  >
@@ -183,6 +184,10 @@ export interface SerializableInspectorState {
183
184
  definitions: InspectorState['secrets']['definitions']
184
185
  files: string[]
185
186
  }
187
+ credentials: {
188
+ definitions: InspectorState['credentials']['definitions']
189
+ files: string[]
190
+ }
186
191
  variables: {
187
192
  definitions: InspectorState['variables']['definitions']
188
193
  files: string[]
@@ -380,6 +385,10 @@ export function serializeInspectorState(
380
385
  definitions: state.secrets.definitions,
381
386
  files: Array.from(state.secrets.files),
382
387
  },
388
+ credentials: {
389
+ definitions: state.credentials.definitions,
390
+ files: Array.from(state.credentials.files),
391
+ },
383
392
  variables: {
384
393
  definitions: state.variables.definitions,
385
394
  files: Array.from(state.variables.files),
@@ -548,6 +557,10 @@ export function deserializeInspectorState(
548
557
  definitions: data.secrets?.definitions || [],
549
558
  files: new Set(data.secrets?.files || []),
550
559
  },
560
+ credentials: {
561
+ definitions: data.credentials?.definitions || [],
562
+ files: new Set(data.credentials?.files || []),
563
+ },
551
564
  variables: {
552
565
  definitions: data.variables?.definitions || [],
553
566
  files: new Set(data.variables?.files || []),
package/src/visit.ts CHANGED
@@ -22,7 +22,8 @@ import { addWireAddon } from './add/add-wire-addon.js'
22
22
  import { addMiddleware } from './add/add-middleware.js'
23
23
  import { addPermission } from './add/add-permission.js'
24
24
  import { addCLI, addCLIRenderers } from './add/add-cli.js'
25
- import { addSecret, addOAuth2Credential } from './add/add-secret.js'
25
+ import { addSecret } from './add/add-secret.js'
26
+ import { addCredential } from './add/add-credential.js'
26
27
  import { addVariable } from './add/add-variable.js'
27
28
  import { addWorkflowGraph } from './add/add-workflow-graph.js'
28
29
  import { addAIAgent } from './add/add-ai-agent.js'
@@ -105,7 +106,7 @@ export const visitRoutes = (
105
106
  ) => {
106
107
  addFunctions(logger, node, checker, state, options)
107
108
  addSecret(logger, node, checker, state, options)
108
- addOAuth2Credential(logger, node, checker, state, options)
109
+ addCredential(logger, node, checker, state, options)
109
110
  addVariable(logger, node, checker, state, options)
110
111
 
111
112
  addHTTPRoute(logger, node, checker, state, options)