@pikku/inspector 0.11.0 → 0.11.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.
Files changed (109) hide show
  1. package/CHANGELOG.md +32 -2
  2. package/dist/add/add-channel.js +11 -10
  3. package/dist/add/add-file-with-factory.js +10 -10
  4. package/dist/add/add-forge-credential.d.ts +8 -0
  5. package/dist/add/add-forge-credential.js +77 -0
  6. package/dist/add/add-forge-node.d.ts +7 -0
  7. package/dist/add/add-forge-node.js +77 -0
  8. package/dist/add/add-functions.js +158 -51
  9. package/dist/add/add-http-route.js +28 -4
  10. package/dist/add/add-mcp-prompt.js +6 -5
  11. package/dist/add/add-mcp-resource.js +6 -5
  12. package/dist/add/add-mcp-tool.js +6 -5
  13. package/dist/add/add-middleware.js +1 -1
  14. package/dist/add/add-permission.js +1 -1
  15. package/dist/add/add-queue-worker.js +6 -5
  16. package/dist/add/add-rpc-invocations.d.ts +3 -0
  17. package/dist/add/add-rpc-invocations.js +51 -25
  18. package/dist/add/add-schedule.js +5 -4
  19. package/dist/add/add-workflow-graph.d.ts +6 -0
  20. package/dist/add/add-workflow-graph.js +659 -0
  21. package/dist/add/add-workflow.d.ts +1 -1
  22. package/dist/add/add-workflow.js +191 -69
  23. package/dist/error-codes.d.ts +3 -0
  24. package/dist/error-codes.js +3 -0
  25. package/dist/index.d.ts +5 -0
  26. package/dist/index.js +3 -0
  27. package/dist/inspector.js +29 -9
  28. package/dist/types.d.ts +47 -8
  29. package/dist/utils/extract-function-name.js +7 -7
  30. package/dist/utils/extract-function-node.d.ts +10 -0
  31. package/dist/utils/extract-function-node.js +38 -0
  32. package/dist/utils/extract-node-value.d.ts +8 -0
  33. package/dist/utils/extract-node-value.js +24 -0
  34. package/dist/utils/extract-service-metadata.d.ts +19 -0
  35. package/dist/utils/extract-service-metadata.js +244 -0
  36. package/dist/utils/get-files-and-methods.d.ts +3 -3
  37. package/dist/utils/get-files-and-methods.js +3 -3
  38. package/dist/utils/get-property-value.d.ts +14 -6
  39. package/dist/utils/get-property-value.js +55 -43
  40. package/dist/utils/post-process.d.ts +9 -0
  41. package/dist/utils/post-process.js +30 -3
  42. package/dist/utils/serialize-inspector-state.d.ts +42 -6
  43. package/dist/utils/serialize-inspector-state.js +36 -10
  44. package/dist/utils/workflow/dsl/deserialize-dsl-workflow.d.ts +24 -0
  45. package/dist/utils/workflow/dsl/deserialize-dsl-workflow.js +898 -0
  46. package/dist/utils/workflow/dsl/extract-dsl-workflow.d.ts +17 -0
  47. package/dist/utils/workflow/dsl/extract-dsl-workflow.js +1284 -0
  48. package/dist/utils/workflow/dsl/index.d.ts +7 -0
  49. package/dist/utils/workflow/dsl/index.js +7 -0
  50. package/dist/utils/workflow/dsl/patterns.d.ts +60 -0
  51. package/dist/utils/workflow/dsl/patterns.js +218 -0
  52. package/dist/utils/workflow/dsl/validation.d.ts +30 -0
  53. package/dist/utils/workflow/dsl/validation.js +142 -0
  54. package/dist/utils/workflow/graph/convert-dsl-to-graph.d.ts +13 -0
  55. package/dist/utils/workflow/graph/convert-dsl-to-graph.js +316 -0
  56. package/dist/utils/workflow/graph/index.d.ts +6 -0
  57. package/dist/utils/workflow/graph/index.js +6 -0
  58. package/dist/utils/workflow/graph/serialize-workflow-graph.d.ts +43 -0
  59. package/dist/utils/workflow/graph/serialize-workflow-graph.js +152 -0
  60. package/dist/utils/workflow/graph/workflow-graph.types.d.ts +229 -0
  61. package/dist/utils/workflow/graph/workflow-graph.types.js +38 -0
  62. package/dist/utils/write-service-metadata.d.ts +13 -0
  63. package/dist/utils/write-service-metadata.js +37 -0
  64. package/dist/visit.js +8 -2
  65. package/package.json +16 -4
  66. package/src/add/add-channel.ts +37 -17
  67. package/src/add/add-file-with-factory.ts +10 -10
  68. package/src/add/add-forge-credential.ts +119 -0
  69. package/src/add/add-forge-node.ts +132 -0
  70. package/src/add/add-functions.ts +199 -69
  71. package/src/add/add-http-route.ts +34 -5
  72. package/src/add/add-mcp-prompt.ts +11 -7
  73. package/src/add/add-mcp-resource.ts +11 -7
  74. package/src/add/add-mcp-tool.ts +11 -7
  75. package/src/add/add-middleware.ts +1 -1
  76. package/src/add/add-permission.ts +1 -1
  77. package/src/add/add-queue-worker.ts +11 -12
  78. package/src/add/add-rpc-invocations.ts +61 -31
  79. package/src/add/add-schedule.ts +10 -5
  80. package/src/add/add-workflow-graph.ts +864 -0
  81. package/src/add/add-workflow.ts +212 -116
  82. package/src/error-codes.ts +3 -0
  83. package/src/index.ts +12 -0
  84. package/src/inspector.ts +36 -10
  85. package/src/types.ts +43 -9
  86. package/src/utils/extract-function-name.ts +7 -7
  87. package/src/utils/extract-function-node.ts +58 -0
  88. package/src/utils/extract-node-value.ts +31 -0
  89. package/src/utils/extract-service-metadata.ts +353 -0
  90. package/src/utils/filter-inspector-state.test.ts +3 -3
  91. package/src/utils/filter-utils.test.ts +45 -51
  92. package/src/utils/get-files-and-methods.ts +11 -11
  93. package/src/utils/get-property-value.ts +67 -53
  94. package/src/utils/permissions.test.ts +3 -3
  95. package/src/utils/post-process.ts +56 -3
  96. package/src/utils/serialize-inspector-state.ts +67 -19
  97. package/src/utils/test-data/inspector-state.json +9 -9
  98. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +1180 -0
  99. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +1608 -0
  100. package/src/utils/workflow/dsl/index.ts +11 -0
  101. package/src/utils/workflow/dsl/patterns.ts +279 -0
  102. package/src/utils/workflow/dsl/validation.ts +180 -0
  103. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +415 -0
  104. package/src/utils/workflow/graph/index.ts +6 -0
  105. package/src/utils/workflow/graph/serialize-workflow-graph.ts +223 -0
  106. package/src/utils/workflow/graph/workflow-graph.types.ts +280 -0
  107. package/src/utils/write-service-metadata.ts +51 -0
  108. package/src/visit.ts +9 -3
  109. package/tsconfig.tsbuildinfo +1 -1
@@ -1,7 +1,7 @@
1
1
  import * as ts from 'typescript'
2
2
  import {
3
3
  getPropertyValue,
4
- getPropertyTags,
4
+ getCommonWireMetaData,
5
5
  } from '../utils/get-property-value.js'
6
6
  import { extractWireNames } from '../utils/post-process.js'
7
7
  import { ensureFunctionMetadata } from '../utils/ensure-function-metadata.js'
@@ -40,10 +40,12 @@ export const addMCPPrompt: AddWiring = (
40
40
  const obj = firstArg
41
41
 
42
42
  const nameValue = getPropertyValue(obj, 'name') as string | null
43
- const descriptionValue = getPropertyValue(obj, 'description') as
44
- | string
45
- | null
46
- const tags = getPropertyTags(obj, 'MCP prompt', nameValue, logger)
43
+ const { tags, summary, description, errors } = getCommonWireMetaData(
44
+ obj,
45
+ 'MCP prompt',
46
+ nameValue,
47
+ logger
48
+ )
47
49
 
48
50
  const funcInitializer = getPropertyAssignmentInitializer(
49
51
  obj,
@@ -76,7 +78,7 @@ export const addMCPPrompt: AddWiring = (
76
78
  return
77
79
  }
78
80
 
79
- if (!descriptionValue) {
81
+ if (!description) {
80
82
  logger.critical(
81
83
  ErrorCode.MISSING_DESCRIPTION,
82
84
  `MCP prompt '${nameValue}' is missing a description.`
@@ -116,7 +118,9 @@ export const addMCPPrompt: AddWiring = (
116
118
  state.mcpEndpoints.promptsMeta[nameValue] = {
117
119
  pikkuFuncName,
118
120
  name: nameValue,
119
- description: descriptionValue,
121
+ description,
122
+ summary,
123
+ errors,
120
124
  tags,
121
125
  inputSchema,
122
126
  outputSchema,
@@ -1,7 +1,7 @@
1
1
  import * as ts from 'typescript'
2
2
  import {
3
3
  getPropertyValue,
4
- getPropertyTags,
4
+ getCommonWireMetaData,
5
5
  } from '../utils/get-property-value.js'
6
6
  import { extractWireNames } from '../utils/post-process.js'
7
7
  import { ensureFunctionMetadata } from '../utils/ensure-function-metadata.js'
@@ -41,11 +41,13 @@ export const addMCPResource: AddWiring = (
41
41
 
42
42
  const uriValue = getPropertyValue(obj, 'uri') as string | null
43
43
  const titleValue = getPropertyValue(obj, 'title') as string | null
44
- const descriptionValue = getPropertyValue(obj, 'description') as
45
- | string
46
- | null
44
+ const { tags, summary, description, errors } = getCommonWireMetaData(
45
+ obj,
46
+ 'MCP resource',
47
+ uriValue,
48
+ logger
49
+ )
47
50
  const streamingValue = getPropertyValue(obj, 'streaming') as boolean | null
48
- const tags = getPropertyTags(obj, 'MCP resource', uriValue, logger)
49
51
 
50
52
  if (streamingValue === true) {
51
53
  logger.warn(
@@ -92,7 +94,7 @@ export const addMCPResource: AddWiring = (
92
94
  return
93
95
  }
94
96
 
95
- if (!descriptionValue) {
97
+ if (!description) {
96
98
  logger.critical(
97
99
  ErrorCode.MISSING_DESCRIPTION,
98
100
  `MCP resource '${uriValue}' is missing a description.`
@@ -133,7 +135,9 @@ export const addMCPResource: AddWiring = (
133
135
  pikkuFuncName,
134
136
  uri: uriValue,
135
137
  title: titleValue,
136
- description: descriptionValue,
138
+ description,
139
+ summary,
140
+ errors,
137
141
  ...(streamingValue !== null && { streaming: streamingValue }),
138
142
  tags,
139
143
  inputSchema,
@@ -1,7 +1,7 @@
1
1
  import * as ts from 'typescript'
2
2
  import {
3
3
  getPropertyValue,
4
- getPropertyTags,
4
+ getCommonWireMetaData,
5
5
  } from '../utils/get-property-value.js'
6
6
  import { extractWireNames } from '../utils/post-process.js'
7
7
  import { ensureFunctionMetadata } from '../utils/ensure-function-metadata.js'
@@ -41,11 +41,13 @@ export const addMCPTool: AddWiring = (
41
41
 
42
42
  const nameValue = getPropertyValue(obj, 'name') as string | null
43
43
  const titleValue = getPropertyValue(obj, 'title') as string | null
44
- const descriptionValue = getPropertyValue(obj, 'description') as
45
- | string
46
- | null
44
+ const { tags, summary, description, errors } = getCommonWireMetaData(
45
+ obj,
46
+ 'MCP tool',
47
+ nameValue,
48
+ logger
49
+ )
47
50
  const streamingValue = getPropertyValue(obj, 'streaming') as boolean | null
48
- const tags = getPropertyTags(obj, 'MCP tool', nameValue, logger)
49
51
 
50
52
  if (streamingValue === true) {
51
53
  logger.warn(
@@ -84,7 +86,7 @@ export const addMCPTool: AddWiring = (
84
86
  return
85
87
  }
86
88
 
87
- if (!descriptionValue) {
89
+ if (!description) {
88
90
  logger.critical(
89
91
  ErrorCode.MISSING_DESCRIPTION,
90
92
  `MCP tool '${nameValue}' is missing a description.`
@@ -125,7 +127,9 @@ export const addMCPTool: AddWiring = (
125
127
  pikkuFuncName,
126
128
  name: nameValue,
127
129
  title: titleValue || undefined,
128
- description: descriptionValue,
130
+ description,
131
+ summary,
132
+ errors,
129
133
  ...(streamingValue !== null && { streaming: streamingValue }),
130
134
  tags,
131
135
  inputSchema,
@@ -125,7 +125,7 @@ export const addMiddleware: AddWiring = (logger, node, checker, state) => {
125
125
  }
126
126
  } else {
127
127
  // No pikkuMiddleware wrapper found - extract from factory's return value directly
128
- // Factory pattern: (config) => (services, interaction, next) => { ... }
128
+ // Factory pattern: (config) => (services, wire, next) => { ... }
129
129
  if (
130
130
  ts.isArrowFunction(factoryNode) ||
131
131
  ts.isFunctionExpression(factoryNode)
@@ -125,7 +125,7 @@ export const addPermission: AddWiring = (logger, node, checker, state) => {
125
125
  }
126
126
  } else {
127
127
  // No pikkuPermission wrapper found - extract from factory's return value directly
128
- // Factory pattern: (config) => (services, data, session) => { ... }
128
+ // Factory pattern: (config) => (services, data, wire) => { ... }
129
129
  if (
130
130
  ts.isArrowFunction(factoryNode) ||
131
131
  ts.isFunctionExpression(factoryNode)
@@ -1,9 +1,8 @@
1
1
  import * as ts from 'typescript'
2
2
  import {
3
3
  getPropertyValue,
4
- getPropertyTags,
4
+ getCommonWireMetaData,
5
5
  } from '../utils/get-property-value.js'
6
- import { PikkuDocs } from '@pikku/core'
7
6
  import { AddWiring } from '../types.js'
8
7
  import { extractFunctionName } from '../utils/extract-function-name.js'
9
8
  import { getPropertyAssignmentInitializer } from '../utils/type-utils.js'
@@ -11,13 +10,7 @@ import { resolveMiddleware } from '../utils/middleware.js'
11
10
  import { extractWireNames } from '../utils/post-process.js'
12
11
  import { ErrorCode } from '../error-codes.js'
13
12
 
14
- export const addQueueWorker: AddWiring = (
15
- logger,
16
- node,
17
- checker,
18
- state,
19
- options
20
- ) => {
13
+ export const addQueueWorker: AddWiring = (logger, node, checker, state) => {
21
14
  if (!ts.isCallExpression(node)) {
22
15
  return
23
16
  }
@@ -39,8 +32,12 @@ export const addQueueWorker: AddWiring = (
39
32
  const obj = firstArg
40
33
 
41
34
  const queueName = getPropertyValue(obj, 'queueName') as string | null
42
- const docs = (getPropertyValue(obj, 'docs') as PikkuDocs) || undefined
43
- const tags = getPropertyTags(obj, 'Queue worker', queueName, logger)
35
+ const { tags, summary, description, errors } = getCommonWireMetaData(
36
+ obj,
37
+ 'Queue worker',
38
+ queueName,
39
+ logger
40
+ )
44
41
 
45
42
  // --- find the referenced function ---
46
43
  const funcInitializer = getPropertyAssignmentInitializer(
@@ -84,7 +81,9 @@ export const addQueueWorker: AddWiring = (
84
81
  state.queueWorkers.meta[queueName] = {
85
82
  pikkuFuncName,
86
83
  queueName,
87
- docs,
84
+ summary,
85
+ description,
86
+ errors,
88
87
  tags,
89
88
  middleware,
90
89
  }
@@ -1,48 +1,78 @@
1
1
  import * as ts from 'typescript'
2
2
  import { InspectorState, InspectorLogger } from '../types.js'
3
3
 
4
+ /**
5
+ * Helper to extract namespace from a namespaced function reference like 'ext:hello'
6
+ */
7
+ function extractNamespace(functionRef: string): string | null {
8
+ const colonIndex = functionRef.indexOf(':')
9
+ if (colonIndex !== -1) {
10
+ return functionRef.substring(0, colonIndex)
11
+ }
12
+ return null
13
+ }
14
+
4
15
  /**
5
16
  * Scan for rpc.invoke() calls to track which functions are actually being invoked
17
+ * Also detects external package usage via:
18
+ * - Namespaced calls: rpc.invoke('namespace:function')
19
+ * - External helper: external('namespace:function')
6
20
  */
7
21
  export function addRPCInvocations(
8
22
  node: ts.Node,
9
23
  state: InspectorState,
10
24
  logger: InspectorLogger
11
25
  ) {
12
- // Look for property access expressions: rpc.invoke
13
- if (ts.isPropertyAccessExpression(node)) {
14
- const { expression, name } = node
26
+ // Look for call expressions: external('ext:hello') or rpc.invoke('...')
27
+ if (ts.isCallExpression(node)) {
28
+ const { expression, arguments: args } = node
29
+
30
+ // Check for external('namespace:function') calls
31
+ if (ts.isIdentifier(expression) && expression.text === 'external') {
32
+ const [firstArg] = args
33
+ if (firstArg && ts.isStringLiteral(firstArg)) {
34
+ const functionRef = firstArg.text
35
+ logger.debug(`• Found external() call: ${functionRef}`)
36
+ state.rpc.invokedFunctions.add(functionRef)
15
37
 
16
- // Check if this is accessing 'invoke' property
17
- if (name.text === 'invoke') {
18
- // Check if the object is 'rpc' (or a variable containing rpc)
19
- if (ts.isIdentifier(expression) && expression.text === 'rpc') {
20
- // This is rpc.invoke - now we need to find the parent call expression
21
- const parent = node.parent
22
- if (ts.isCallExpression(parent) && parent.expression === node) {
23
- // This is rpc.invoke('function-name')
24
- const [firstArg] = parent.arguments
25
- if (firstArg) {
26
- // Extract the function name from string literal
27
- if (ts.isStringLiteral(firstArg)) {
28
- const functionName = firstArg.text
29
- logger.debug(`• Found RPC invocation: ${functionName}`)
30
- state.rpc.invokedFunctions.add(functionName)
31
- }
32
- // Handle template literals like `function-${name}`
33
- else if (
34
- ts.isTemplateExpression(firstArg) ||
35
- ts.isNoSubstitutionTemplateLiteral(firstArg)
36
- ) {
37
- logger.warn(
38
- `• Found dynamic RPC invocation: ${firstArg.getText()}`
39
- )
40
- logger.warn(
41
- `\tYou can only use string literals for RPC function names, with ' or " and not \``
42
- )
43
- }
38
+ const namespace = extractNamespace(functionRef)
39
+ if (namespace) {
40
+ logger.debug(` → External package detected: ${namespace}`)
41
+ state.rpc.usedExternalPackages.add(namespace)
42
+ }
43
+ }
44
+ }
45
+
46
+ // Check for rpc.invoke('...') calls
47
+ if (
48
+ ts.isPropertyAccessExpression(expression) &&
49
+ expression.name.text === 'invoke' &&
50
+ ts.isIdentifier(expression.expression) &&
51
+ expression.expression.text === 'rpc'
52
+ ) {
53
+ const [firstArg] = args
54
+ if (firstArg) {
55
+ if (ts.isStringLiteral(firstArg)) {
56
+ const functionRef = firstArg.text
57
+ logger.debug(`• Found RPC invocation: ${functionRef}`)
58
+ state.rpc.invokedFunctions.add(functionRef)
59
+
60
+ const namespace = extractNamespace(functionRef)
61
+ if (namespace) {
62
+ logger.debug(` → External package detected: ${namespace}`)
63
+ state.rpc.usedExternalPackages.add(namespace)
44
64
  }
45
65
  }
66
+ // Handle template literals like `function-${name}`
67
+ else if (
68
+ ts.isTemplateExpression(firstArg) ||
69
+ ts.isNoSubstitutionTemplateLiteral(firstArg)
70
+ ) {
71
+ logger.warn(`• Found dynamic RPC invocation: ${firstArg.getText()}`)
72
+ logger.warn(
73
+ `\tYou can only use string literals for RPC function names, with ' or " and not \``
74
+ )
75
+ }
46
76
  }
47
77
  }
48
78
  }
@@ -1,9 +1,8 @@
1
1
  import * as ts from 'typescript'
2
2
  import {
3
3
  getPropertyValue,
4
- getPropertyTags,
4
+ getCommonWireMetaData,
5
5
  } from '../utils/get-property-value.js'
6
- import { PikkuDocs } from '@pikku/core'
7
6
  import { AddWiring } from '../types.js'
8
7
  import { extractFunctionName } from '../utils/extract-function-name.js'
9
8
  import { getPropertyAssignmentInitializer } from '../utils/type-utils.js'
@@ -40,8 +39,12 @@ export const addSchedule: AddWiring = (
40
39
 
41
40
  const nameValue = getPropertyValue(obj, 'name') as string | null
42
41
  const scheduleValue = getPropertyValue(obj, 'schedule') as string | null
43
- const docs = (getPropertyValue(obj, 'docs') as PikkuDocs) || undefined
44
- const tags = getPropertyTags(obj, 'Scheduler', nameValue, logger)
42
+ const { tags, summary, description, errors } = getCommonWireMetaData(
43
+ obj,
44
+ 'Scheduler',
45
+ nameValue,
46
+ logger
47
+ )
45
48
 
46
49
  const funcInitializer = getPropertyAssignmentInitializer(
47
50
  obj,
@@ -81,7 +84,9 @@ export const addSchedule: AddWiring = (
81
84
  pikkuFuncName,
82
85
  name: nameValue,
83
86
  schedule: scheduleValue,
84
- docs,
87
+ summary,
88
+ description,
89
+ errors,
85
90
  tags,
86
91
  middleware,
87
92
  }