Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af6ad2c4ac | ||
|
|
9446d602a4 | ||
|
|
9739430845 | ||
|
|
e105a5ce41 | ||
|
|
65a8d298fc | ||
|
|
1f6750a867 | ||
|
|
3a4bd7a335 | ||
|
|
09488142e3 | ||
|
|
c729573012 | ||
|
|
fa073b82c5 | ||
|
|
1157ae8180 | ||
|
|
39e1ff891d | ||
|
|
2da133cc84 | ||
|
|
121a7cf487 | ||
|
|
e06ed630a2 | ||
|
|
230b1cd3d0 | ||
|
|
3d8acac3cb | ||
|
|
d46015cb8d | ||
|
|
b44f5a29f4 | ||
|
|
a6d96d58d5 | ||
|
|
4eebe5ea25 | ||
|
|
cf1eafb00d | ||
|
|
debf34cf91 | ||
|
|
541dd69625 | ||
|
|
f65d1a34dc | ||
|
|
9d962e5274 | ||
|
|
8b38b47848 | ||
|
|
b7792492cd | ||
|
|
a2600c61b7 | ||
|
|
306ffe21b9 | ||
|
|
326b9a12f4 | ||
|
|
8207a8ca01 | ||
|
|
c6c19e0fb7 | ||
|
|
e09e659817 | ||
|
|
e608d2ba8a | ||
|
|
27965bc3a4 | ||
|
|
a8bddad5e5 | ||
|
|
672ba8a3ac | ||
|
|
3a80d137e1 | ||
|
|
074e8b294d | ||
|
|
f1ca66fc66 | ||
|
|
6360e0db9b |
2
.github/workflows/check-dist.yml
vendored
2
.github/workflows/check-dist.yml
vendored
@@ -43,7 +43,7 @@ jobs:
|
||||
|
||||
- name: Build dist/ Directory
|
||||
id: build
|
||||
run: npm run bundle
|
||||
run: npm run package
|
||||
|
||||
# This will fail the workflow if the `dist/` directory is different than
|
||||
# expected.
|
||||
|
||||
2
.github/workflows/licensed.yml
vendored
2
.github/workflows/licensed.yml
vendored
@@ -42,7 +42,7 @@ jobs:
|
||||
|
||||
- name: Setup Ruby
|
||||
id: setup-ruby
|
||||
uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71
|
||||
uses: ruby/setup-ruby@4eb9f110bac952a8b68ecf92e3b5c7a987594ba6
|
||||
with:
|
||||
ruby-version: ruby
|
||||
|
||||
|
||||
2
.github/workflows/linter.yml
vendored
2
.github/workflows/linter.yml
vendored
@@ -38,7 +38,7 @@ jobs:
|
||||
|
||||
- name: Lint Codebase
|
||||
id: super-linter
|
||||
uses: super-linter/super-linter/slim@5119dcd8011e92182ce8219d9e9efc82f16fddb6
|
||||
uses: super-linter/super-linter/slim@61abc07d755095a68f4987d1c2c3d1d64408f1f9
|
||||
env:
|
||||
DEFAULT_BRANCH: main
|
||||
FILTER_REGEX_EXCLUDE: dist/**/*
|
||||
|
||||
@@ -16,6 +16,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Update the ${{ env.TAG_NAME }} tag
|
||||
uses: actions/publish-action@v0.3.0
|
||||
uses: actions/publish-action@v0.4.0
|
||||
with:
|
||||
source-tag: ${{ env.TAG_NAME }}
|
||||
|
||||
62
README.md
62
README.md
@@ -123,6 +123,33 @@ supplied via the `input` parameter in YAML format. Additionally, you can
|
||||
provide file-based variables via `file_input`, where each key maps to a file
|
||||
path.
|
||||
|
||||
### Prompt.yml with model parameters
|
||||
|
||||
You can specify model parameters directly in your `.prompt.yml` files using the
|
||||
`modelParameters` key:
|
||||
|
||||
```yaml
|
||||
messages:
|
||||
- role: system
|
||||
content: Be as concise as possible
|
||||
- role: user
|
||||
content: 'Compare {{a}} and {{b}}, please'
|
||||
model: openai/gpt-4o
|
||||
modelParameters:
|
||||
maxCompletionTokens: 500
|
||||
temperature: 0.7
|
||||
```
|
||||
|
||||
| Key | Type | Description |
|
||||
| --------------------- | ------ | ----------------------------------------------------- |
|
||||
| `maxCompletionTokens` | number | The maximum number of tokens to generate |
|
||||
| `maxTokens` | number | The maximum number of tokens to generate (deprecated) |
|
||||
| `temperature` | number | The sampling temperature to use (0-1) |
|
||||
| `topP` | number | The nucleus sampling parameter to use (0-1) |
|
||||
|
||||
> ![Note]
|
||||
> Parameters set in `modelParameters` take precedence over the corresponding action inputs.
|
||||
|
||||
### Using a system prompt file
|
||||
|
||||
In addition to the regular prompt, you can provide a system prompt file instead
|
||||
@@ -276,23 +303,24 @@ perform actions like searching issues and PRs.
|
||||
Various inputs are defined in [`action.yml`](action.yml) to let you configure
|
||||
the action:
|
||||
|
||||
| Name | Description | Default |
|
||||
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ |
|
||||
| `token` | Token to use for inference. Typically the GITHUB_TOKEN secret | `github.token` |
|
||||
| `prompt` | The prompt to send to the model | N/A |
|
||||
| `prompt-file` | Path to a file containing the prompt (supports .txt and .prompt.yml formats). If both `prompt` and `prompt-file` are provided, `prompt-file` takes precedence | `""` |
|
||||
| `input` | Template variables in YAML format for .prompt.yml files (e.g., `var1: value1` on separate lines) | `""` |
|
||||
| `file_input` | Template variables in YAML where values are file paths. The file contents are read and used for templating | `""` |
|
||||
| `system-prompt` | The system prompt to send to the model | `"You are a helpful assistant"` |
|
||||
| `system-prompt-file` | Path to a file containing the system prompt. If both `system-prompt` and `system-prompt-file` are provided, `system-prompt-file` takes precedence | `""` |
|
||||
| `model` | The model to use for inference. Must be available in the [GitHub Models](https://github.com/marketplace?type=models) catalog | `openai/gpt-4o` |
|
||||
| `endpoint` | The endpoint to use for inference. If you're running this as part of an org, you should probably use the org-specific Models endpoint | `https://models.github.ai/inference` |
|
||||
| `max-tokens` | The max number of tokens to generate | 200 |
|
||||
| `temperature` | The sampling temperature to use (0-1) | `""` |
|
||||
| `top-p` | The nucleus sampling parameter to use (0-1) | `""` |
|
||||
| `enable-github-mcp` | Enable Model Context Protocol integration with GitHub tools | `false` |
|
||||
| `github-mcp-token` | Token to use for GitHub MCP server (defaults to the main token if not specified). | `""` |
|
||||
| `custom-headers` | Custom HTTP headers to include in API requests. Supports both YAML format (`header1: value1`) and JSON format (`{"header1": "value1"}`). Useful for API Management platforms, rate limiting, and request tracking. | `""` |
|
||||
| Name | Description | Default |
|
||||
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ |
|
||||
| `token` | Token to use for inference. Typically the GITHUB_TOKEN secret | `github.token` |
|
||||
| `prompt` | The prompt to send to the model | N/A |
|
||||
| `prompt-file` | Path to a file containing the prompt (supports .txt and .prompt.yml formats). If both `prompt` and `prompt-file` are provided, `prompt-file` takes precedence | `""` |
|
||||
| `input` | Template variables in YAML format for .prompt.yml files (e.g., `var1: value1` on separate lines) | `""` |
|
||||
| `file_input` | Template variables in YAML where values are file paths. The file contents are read and used for templating | `""` |
|
||||
| `system-prompt` | The system prompt to send to the model | `"You are a helpful assistant"` |
|
||||
| `system-prompt-file` | Path to a file containing the system prompt. If both `system-prompt` and `system-prompt-file` are provided, `system-prompt-file` takes precedence | `""` |
|
||||
| `model` | The model to use for inference. Must be available in the [GitHub Models](https://github.com/marketplace?type=models) catalog | `openai/gpt-4o` |
|
||||
| `endpoint` | The endpoint to use for inference. If you're running this as part of an org, you should probably use the org-specific Models endpoint | `https://models.github.ai/inference` |
|
||||
| `max-tokens` | The maximum number of tokens to generate (deprecated, use `max-completion-tokens` instead) | 200 |
|
||||
| `max-completion-tokens` | The maximum number of tokens to generate | `""` |
|
||||
| `temperature` | The sampling temperature to use (0-1) | `""` |
|
||||
| `top-p` | The nucleus sampling parameter to use (0-1) | `""` |
|
||||
| `enable-github-mcp` | Enable Model Context Protocol integration with GitHub tools | `false` |
|
||||
| `github-mcp-token` | Token to use for GitHub MCP server (defaults to the main token if not specified). | `""` |
|
||||
| `custom-headers` | Custom HTTP headers to include in API requests. Supports both YAML format (`header1: value1`) and JSON format (`{"header1": "value1"}`). Useful for API Management platforms, rate limiting, and request tracking. | `""` |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
@@ -9,3 +9,4 @@ export const getBooleanInput = vi.fn<typeof core.getBooleanInput>()
|
||||
export const setOutput = vi.fn<typeof core.setOutput>()
|
||||
export const setFailed = vi.fn<typeof core.setFailed>()
|
||||
export const warning = vi.fn<typeof core.warning>()
|
||||
export const setSecret = vi.fn<typeof core.setSecret>()
|
||||
|
||||
@@ -109,6 +109,7 @@ describe('helpers.ts - inference request building', () => {
|
||||
undefined,
|
||||
undefined,
|
||||
100,
|
||||
undefined,
|
||||
'https://api.test.com',
|
||||
'test-token',
|
||||
)
|
||||
@@ -122,6 +123,7 @@ describe('helpers.ts - inference request building', () => {
|
||||
temperature: undefined,
|
||||
topP: undefined,
|
||||
maxTokens: 100,
|
||||
maxCompletionTokens: undefined,
|
||||
endpoint: 'https://api.test.com',
|
||||
token: 'test-token',
|
||||
responseFormat: {
|
||||
@@ -143,6 +145,7 @@ describe('helpers.ts - inference request building', () => {
|
||||
undefined,
|
||||
undefined,
|
||||
100,
|
||||
undefined,
|
||||
'https://api.test.com',
|
||||
'test-token',
|
||||
)
|
||||
@@ -156,6 +159,7 @@ describe('helpers.ts - inference request building', () => {
|
||||
temperature: undefined,
|
||||
topP: undefined,
|
||||
maxTokens: 100,
|
||||
maxCompletionTokens: undefined,
|
||||
endpoint: 'https://api.test.com',
|
||||
token: 'test-token',
|
||||
responseFormat: undefined,
|
||||
|
||||
@@ -150,9 +150,9 @@ X-Custom-Header: custom-value`
|
||||
header2: 'value2',
|
||||
'X-Custom-Header': 'custom-value',
|
||||
})
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: header1: value1')
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: header2: value2')
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: X-Custom-Header: custom-value')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: header1: value1')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: header2: value2')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: X-Custom-Header: custom-value')
|
||||
})
|
||||
|
||||
it('parses JSON format headers correctly', () => {
|
||||
@@ -165,9 +165,9 @@ X-Custom-Header: custom-value`
|
||||
header2: 'value2',
|
||||
'X-Team': 'engineering',
|
||||
})
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: header1: value1')
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: header2: value2')
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: X-Team: engineering')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: header1: value1')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: header2: value2')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: X-Team: engineering')
|
||||
})
|
||||
|
||||
it('returns empty object for empty input', () => {
|
||||
@@ -194,13 +194,13 @@ password: pass123`
|
||||
})
|
||||
|
||||
// Sensitive headers should be masked
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: Ocp-Apim-Subscription-Key: ***MASKED***')
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: X-Api-Token: ***MASKED***')
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: Authorization: ***MASKED***')
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: password: ***MASKED***')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: Ocp-Apim-Subscription-Key: ***MASKED***')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: X-Api-Token: ***MASKED***')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: Authorization: ***MASKED***')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: password: ***MASKED***')
|
||||
|
||||
// Non-sensitive headers should not be masked
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: serviceName: my-service')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: serviceName: my-service')
|
||||
})
|
||||
|
||||
it('validates header names and skips invalid ones', () => {
|
||||
@@ -214,13 +214,11 @@ valid123: value5`
|
||||
|
||||
expect(result).toEqual({
|
||||
'valid-header': 'value1',
|
||||
invalid_underscore: 'value3',
|
||||
valid123: 'value5',
|
||||
})
|
||||
|
||||
expect(core.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping invalid header name: invalid header'))
|
||||
expect(core.warning).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Skipping invalid header name: invalid_underscore'),
|
||||
)
|
||||
expect(core.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping invalid header name: invalid@header'))
|
||||
})
|
||||
|
||||
@@ -367,8 +365,8 @@ systemID: terraform-ci`
|
||||
})
|
||||
|
||||
// Only the subscription key should be masked
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: Ocp-Apim-Subscription-Key: ***MASKED***')
|
||||
expect(core.info).toHaveBeenCalledWith('Custom header added: serviceName: terraform-plan-workflow')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: Ocp-Apim-Subscription-Key: ***MASKED***')
|
||||
expect(core.debug).toHaveBeenCalledWith('Custom header added: serviceName: terraform-plan-workflow')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('inference.ts', () => {
|
||||
{role: 'user' as const, content: 'Hello, AI!'},
|
||||
],
|
||||
modelName: 'gpt-4',
|
||||
maxTokens: 100,
|
||||
maxCompletionTokens: 100,
|
||||
endpoint: 'https://api.test.com',
|
||||
token: 'test-token',
|
||||
}
|
||||
@@ -58,7 +58,7 @@ describe('inference.ts', () => {
|
||||
|
||||
expect(result).toBe('Hello, user!')
|
||||
expect(core.info).toHaveBeenCalledWith('Running simple inference without tools')
|
||||
expect(core.info).toHaveBeenCalledWith('Model response: Hello, user!')
|
||||
expect(core.debug).toHaveBeenCalledWith('Model response: Hello, user!')
|
||||
|
||||
// Verify the request structure
|
||||
expect(mockCreate).toHaveBeenCalledWith({
|
||||
@@ -136,7 +136,7 @@ describe('inference.ts', () => {
|
||||
const result = await simpleInference(mockRequest)
|
||||
|
||||
expect(result).toBeNull()
|
||||
expect(core.info).toHaveBeenCalledWith('Model response: No response content')
|
||||
expect(core.debug).toHaveBeenCalledWith('Model response: No response content')
|
||||
})
|
||||
|
||||
it('includes response format when specified', async () => {
|
||||
@@ -633,4 +633,64 @@ describe('inference.ts', () => {
|
||||
expect(result).toBe('{"immediate": "result"}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('token param routing', () => {
|
||||
it('sends max_tokens when only maxTokens is set', async () => {
|
||||
const requestWithMaxTokens = {
|
||||
...mockRequest,
|
||||
maxCompletionTokens: undefined,
|
||||
maxTokens: 100,
|
||||
}
|
||||
|
||||
const mockResponse = {
|
||||
choices: [
|
||||
{
|
||||
message: {
|
||||
content: 'Direct max_tokens response',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
mockCreate.mockResolvedValueOnce(mockResponse)
|
||||
|
||||
const result = await simpleInference(requestWithMaxTokens)
|
||||
|
||||
expect(result).toBe('Direct max_tokens response')
|
||||
expect(mockCreate).toHaveBeenCalledTimes(1)
|
||||
|
||||
// Should have sent max_tokens directly
|
||||
expect(mockCreate.mock.calls[0][0]).toHaveProperty('max_tokens', 100)
|
||||
expect(mockCreate.mock.calls[0][0]).not.toHaveProperty('max_completion_tokens')
|
||||
})
|
||||
|
||||
it('sends neither token param when both are undefined', async () => {
|
||||
const requestWithNoTokens = {
|
||||
...mockRequest,
|
||||
maxCompletionTokens: undefined,
|
||||
maxTokens: undefined,
|
||||
}
|
||||
|
||||
const mockResponse = {
|
||||
choices: [
|
||||
{
|
||||
message: {
|
||||
content: 'No token limit response',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
mockCreate.mockResolvedValueOnce(mockResponse)
|
||||
|
||||
const result = await simpleInference(requestWithNoTokens)
|
||||
|
||||
expect(result).toBe('No token limit response')
|
||||
expect(mockCreate).toHaveBeenCalledTimes(1)
|
||||
|
||||
const params = mockCreate.mock.calls[0][0]
|
||||
expect(params).not.toHaveProperty('max_tokens')
|
||||
expect(params).not.toHaveProperty('max_completion_tokens')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -136,6 +136,7 @@ describe('main.ts', () => {
|
||||
await run()
|
||||
|
||||
expect(core.setOutput).toHaveBeenCalled()
|
||||
expect(core.setSecret).toHaveBeenCalledWith('fake-token')
|
||||
verifyStandardResponse()
|
||||
expect(mockProcessExit).toHaveBeenCalledWith(0)
|
||||
})
|
||||
@@ -168,6 +169,7 @@ describe('main.ts', () => {
|
||||
],
|
||||
modelName: 'gpt-4',
|
||||
maxTokens: 100,
|
||||
maxCompletionTokens: undefined,
|
||||
endpoint: 'https://api.test.com',
|
||||
token: 'fake-token',
|
||||
responseFormat: undefined,
|
||||
@@ -198,6 +200,7 @@ describe('main.ts', () => {
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setSecret).toHaveBeenCalledWith('fake-token')
|
||||
expect(mockConnectToGitHubMCP).toHaveBeenCalledWith('fake-token', '')
|
||||
expect(mockMcpInference).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
@@ -259,6 +262,7 @@ describe('main.ts', () => {
|
||||
],
|
||||
modelName: 'gpt-4',
|
||||
maxTokens: 100,
|
||||
maxCompletionTokens: undefined,
|
||||
endpoint: 'https://api.test.com',
|
||||
token: 'fake-token',
|
||||
responseFormat: undefined,
|
||||
|
||||
@@ -177,8 +177,8 @@ describe('mcp.ts', () => {
|
||||
name: 'test-tool',
|
||||
content: JSON.stringify(toolResult.content),
|
||||
})
|
||||
expect(core.info).toHaveBeenCalledWith('Executing GitHub MCP tool: test-tool with args: {"param": "value"}')
|
||||
expect(core.info).toHaveBeenCalledWith('GitHub MCP tool test-tool executed successfully')
|
||||
expect(core.debug).toHaveBeenCalledWith('Executing GitHub MCP tool: test-tool with args: {"param": "value"}')
|
||||
expect(core.debug).toHaveBeenCalledWith('GitHub MCP tool test-tool executed successfully')
|
||||
})
|
||||
|
||||
it('handles tool execution errors gracefully', async () => {
|
||||
|
||||
@@ -135,5 +135,17 @@ describe('prompt.ts', () => {
|
||||
it('errors on missing files', () => {
|
||||
expect(() => parseFileTemplateVariables('x: ./does-not-exist.txt')).toThrow('was not found')
|
||||
})
|
||||
|
||||
it('errors on non-string file paths', () => {
|
||||
expect(() => parseFileTemplateVariables('x: 123')).toThrow(
|
||||
"File template variable 'x' must be a string file path",
|
||||
)
|
||||
expect(() => parseFileTemplateVariables('x: true')).toThrow(
|
||||
"File template variable 'x' must be a string file path",
|
||||
)
|
||||
expect(() => parseFileTemplateVariables('x: { nested: "object" }')).toThrow(
|
||||
"File template variable 'x' must be a string file path",
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -43,9 +43,13 @@ inputs:
|
||||
required: false
|
||||
default: ''
|
||||
max-tokens:
|
||||
description: The maximum number of tokens to generate
|
||||
description: The maximum number of tokens to generate (deprecated)
|
||||
required: false
|
||||
default: '200'
|
||||
max-completion-tokens:
|
||||
description: The maximum number of tokens to generate
|
||||
required: false
|
||||
default: ''
|
||||
temperature:
|
||||
description: The sampling temperature to use (0-1)
|
||||
required: false
|
||||
|
||||
34
dist/index.js
generated
vendored
34
dist/index.js
generated
vendored
@@ -58300,6 +58300,19 @@ OpenAI.Responses = Responses;
|
||||
OpenAI.Evals = Evals;
|
||||
OpenAI.Containers = Containers;
|
||||
|
||||
/**
|
||||
* Build according to what input was passed, default to max_tokens.
|
||||
* Only one of max_tokens or max_completion_tokens will be set.
|
||||
*/
|
||||
function buildMaxTokensParam(request) {
|
||||
if (request.maxCompletionTokens != null) {
|
||||
return { max_completion_tokens: request.maxCompletionTokens };
|
||||
}
|
||||
if (request.maxTokens != null) {
|
||||
return { max_tokens: request.maxTokens };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
/**
|
||||
* Simple one-shot inference without tools
|
||||
*/
|
||||
@@ -58312,10 +58325,10 @@ async function simpleInference(request) {
|
||||
});
|
||||
const chatCompletionRequest = {
|
||||
messages: request.messages,
|
||||
max_completion_tokens: request.maxTokens,
|
||||
model: request.modelName,
|
||||
temperature: request.temperature,
|
||||
top_p: request.topP,
|
||||
...buildMaxTokensParam(request), // Note: solution around models using different underlying max tokens properties
|
||||
};
|
||||
// Add response format if specified
|
||||
if (request.responseFormat) {
|
||||
@@ -58349,10 +58362,10 @@ async function mcpInference(request, githubMcpClient) {
|
||||
coreExports.info(`MCP inference iteration ${iterationCount}`);
|
||||
const chatCompletionRequest = {
|
||||
messages: messages,
|
||||
max_completion_tokens: request.maxTokens,
|
||||
model: request.modelName,
|
||||
temperature: request.temperature,
|
||||
top_p: request.topP,
|
||||
...buildMaxTokensParam(request), // Note: solution around models using different underlying max tokens properties
|
||||
};
|
||||
// Add response format if specified (only on final iteration to avoid conflicts with tool calls)
|
||||
if (finalMessage && request.responseFormat) {
|
||||
@@ -61382,7 +61395,8 @@ function validateAndMaskHeaders(headers) {
|
||||
/**
|
||||
* Build complete InferenceRequest from prompt config and inputs
|
||||
*/
|
||||
function buildInferenceRequest(promptConfig, systemPrompt, prompt, modelName, temperature, topP, maxTokens, endpoint, token, customHeaders) {
|
||||
function buildInferenceRequest(promptConfig, systemPrompt, prompt, modelName, temperature, topP, maxTokens, // Deprecated
|
||||
maxCompletionTokens, endpoint, token, customHeaders) {
|
||||
const messages = buildMessages(promptConfig, systemPrompt, prompt);
|
||||
const responseFormat = buildResponseFormat(promptConfig);
|
||||
return {
|
||||
@@ -61390,7 +61404,8 @@ function buildInferenceRequest(promptConfig, systemPrompt, prompt, modelName, te
|
||||
modelName,
|
||||
temperature,
|
||||
topP,
|
||||
maxTokens,
|
||||
maxTokens, // Deprecated
|
||||
maxCompletionTokens,
|
||||
endpoint,
|
||||
token,
|
||||
responseFormat,
|
||||
@@ -61536,10 +61551,11 @@ async function run() {
|
||||
}
|
||||
// Get common parameters
|
||||
const modelName = promptConfig?.model || coreExports.getInput('model');
|
||||
let maxTokens = promptConfig?.modelParameters?.maxTokens ?? coreExports.getInput('max-tokens');
|
||||
if (typeof maxTokens === 'string') {
|
||||
maxTokens = parseInt(maxTokens, 10);
|
||||
}
|
||||
// Parse token limit inputs
|
||||
const maxCompletionTokensInput = promptConfig?.modelParameters?.maxCompletionTokens ?? coreExports.getInput('max-completion-tokens');
|
||||
const maxCompletionTokens = maxCompletionTokensInput ? Number(maxCompletionTokensInput) : undefined;
|
||||
const maxTokensInput = promptConfig?.modelParameters?.maxTokens ?? coreExports.getInput('max-tokens');
|
||||
const maxTokens = maxCompletionTokens != null ? undefined : maxTokensInput ? Number(maxTokensInput) : undefined;
|
||||
const token = process.env['GITHUB_TOKEN'] || coreExports.getInput('token');
|
||||
if (token === undefined) {
|
||||
throw new Error('GITHUB_TOKEN is not set');
|
||||
@@ -61557,7 +61573,7 @@ async function run() {
|
||||
const customHeadersInput = coreExports.getInput('custom-headers');
|
||||
const customHeaders = parseCustomHeaders(customHeadersInput);
|
||||
// Build the inference request with pre-processed messages and response format
|
||||
const inferenceRequest = buildInferenceRequest(promptConfig, systemPrompt, prompt, modelName, temperature, topP, maxTokens, endpoint, token, customHeaders);
|
||||
const inferenceRequest = buildInferenceRequest(promptConfig, systemPrompt, prompt, modelName, temperature, topP, maxTokens, maxCompletionTokens, endpoint, token, customHeaders);
|
||||
const enableMcp = coreExports.getBooleanInput('enable-github-mcp') || false;
|
||||
let modelResponse = null;
|
||||
if (enableMcp) {
|
||||
|
||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -46,7 +46,7 @@ export default [
|
||||
|
||||
parserOptions: {
|
||||
project: ['tsconfig.eslint.json'],
|
||||
tsconfigRootDir: '.',
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
984
package-lock.json
generated
984
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@@ -23,11 +23,11 @@
|
||||
"license": "MIT",
|
||||
"prettier": "@github/prettier-config",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
"@modelcontextprotocol/sdk": "^1.25.2",
|
||||
"@actions/core": "^3.0.0",
|
||||
"@modelcontextprotocol/sdk": "^1.26.0",
|
||||
"@types/tmp": "^0.2.6",
|
||||
"js-yaml": "^4.1.1",
|
||||
"openai": "^5.11.0",
|
||||
"openai": "^6.28.0",
|
||||
"pkce-challenge": "^5.0.0",
|
||||
"tmp": "^0.2.4"
|
||||
},
|
||||
@@ -37,21 +37,21 @@
|
||||
"@github/prettier-config": "^0.0.6",
|
||||
"@rollup/plugin-commonjs": "^28.0.5",
|
||||
"@rollup/plugin-json": "^6.1.0",
|
||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||
"@rollup/plugin-typescript": "^12.1.2",
|
||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||
"@rollup/plugin-typescript": "^12.3.0",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/node": "^24.1.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.34.0",
|
||||
"@types/node": "^24.12.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.57.0",
|
||||
"@typescript-eslint/parser": "^8.32.1",
|
||||
"eslint": "^9.29.0",
|
||||
"eslint-config-prettier": "^10.1.5",
|
||||
"eslint-import-resolver-typescript": "^4.4.3",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-prettier": "^5.4.1",
|
||||
"prettier": "^3.5.3",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-import-resolver-typescript": "^4.4.4",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-prettier": "^5.5.5",
|
||||
"prettier": "^3.8.1",
|
||||
"prettier-eslint": "^16.4.2",
|
||||
"rollup": "^4.43.0",
|
||||
"typescript": "^5.8.3",
|
||||
"rollup": "^4.59.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^3"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
||||
@@ -121,9 +121,10 @@ function validateAndMaskHeaders(headers: Record<string, unknown>): Record<string
|
||||
const sensitivePatterns = ['key', 'token', 'secret', 'password', 'authorization']
|
||||
|
||||
for (const [name, value] of Object.entries(headers)) {
|
||||
// Validate header name (basic HTTP header name validation, RFC 7230: letters, digits, and hyphens)
|
||||
if (!/^[A-Za-z0-9-]+$/.test(name)) {
|
||||
core.warning(`Skipping invalid header name: ${name} (only alphanumeric characters and hyphens allowed)`)
|
||||
// Validate header name (RFC 7230: token = 1*tchar)
|
||||
// tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
|
||||
if (!/^[A-Za-z0-9!#$%&'*+\-.^_`|~]+$/.test(name)) {
|
||||
core.warning(`Skipping invalid header name: ${name} (contains invalid characters)`)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -143,9 +144,9 @@ function validateAndMaskHeaders(headers: Record<string, unknown>): Record<string
|
||||
const lowerName = name.toLowerCase()
|
||||
const isSensitive = sensitivePatterns.some(pattern => lowerName.includes(pattern))
|
||||
if (isSensitive) {
|
||||
core.info(`Custom header added: ${name}: ***MASKED***`)
|
||||
core.debug(`Custom header added: ${name}: ***MASKED***`)
|
||||
} else {
|
||||
core.info(`Custom header added: ${name}: ${stringValue}`)
|
||||
core.debug(`Custom header added: ${name}: ${stringValue}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +163,8 @@ export function buildInferenceRequest(
|
||||
modelName: string,
|
||||
temperature: number | undefined,
|
||||
topP: number | undefined,
|
||||
maxTokens: number,
|
||||
maxTokens: number | undefined, // Deprecated
|
||||
maxCompletionTokens: number | undefined,
|
||||
endpoint: string,
|
||||
token: string,
|
||||
customHeaders?: Record<string, string>,
|
||||
@@ -175,7 +177,8 @@ export function buildInferenceRequest(
|
||||
modelName,
|
||||
temperature,
|
||||
topP,
|
||||
maxTokens,
|
||||
maxTokens, // Deprecated
|
||||
maxCompletionTokens,
|
||||
endpoint,
|
||||
token,
|
||||
responseFormat,
|
||||
|
||||
@@ -12,7 +12,8 @@ interface ChatMessage {
|
||||
export interface InferenceRequest {
|
||||
messages: Array<{role: 'system' | 'user' | 'assistant' | 'tool'; content: string}>
|
||||
modelName: string
|
||||
maxTokens: number
|
||||
maxTokens?: number // Deprecated
|
||||
maxCompletionTokens?: number
|
||||
endpoint: string
|
||||
token: string
|
||||
temperature?: number
|
||||
@@ -33,6 +34,20 @@ export interface InferenceResponse {
|
||||
}>
|
||||
}
|
||||
|
||||
/**
|
||||
* Build according to what input was passed, default to max_tokens.
|
||||
* Only one of max_tokens or max_completion_tokens will be set.
|
||||
*/
|
||||
function buildMaxTokensParam(request: InferenceRequest): {max_tokens?: number; max_completion_tokens?: number} {
|
||||
if (request.maxCompletionTokens != null) {
|
||||
return {max_completion_tokens: request.maxCompletionTokens}
|
||||
}
|
||||
if (request.maxTokens != null) {
|
||||
return {max_tokens: request.maxTokens}
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple one-shot inference without tools
|
||||
*/
|
||||
@@ -47,10 +62,10 @@ export async function simpleInference(request: InferenceRequest): Promise<string
|
||||
|
||||
const chatCompletionRequest: OpenAI.Chat.Completions.ChatCompletionCreateParams = {
|
||||
messages: request.messages as OpenAI.Chat.Completions.ChatCompletionMessageParam[],
|
||||
max_completion_tokens: request.maxTokens,
|
||||
model: request.modelName,
|
||||
temperature: request.temperature,
|
||||
top_p: request.topP,
|
||||
...buildMaxTokensParam(request), // Note: solution around models using different underlying max tokens properties
|
||||
}
|
||||
|
||||
// Add response format if specified
|
||||
@@ -61,7 +76,7 @@ export async function simpleInference(request: InferenceRequest): Promise<string
|
||||
|
||||
const response = await chatCompletion(client, chatCompletionRequest, 'simpleInference')
|
||||
const modelResponse = response.choices[0]?.message?.content
|
||||
core.info(`Model response: ${modelResponse || 'No response content'}`)
|
||||
core.debug(`Model response: ${modelResponse || 'No response content'}`)
|
||||
return modelResponse || null
|
||||
}
|
||||
|
||||
@@ -95,10 +110,10 @@ export async function mcpInference(
|
||||
|
||||
const chatCompletionRequest: OpenAI.Chat.Completions.ChatCompletionCreateParams = {
|
||||
messages: messages as OpenAI.Chat.Completions.ChatCompletionMessageParam[],
|
||||
max_completion_tokens: request.maxTokens,
|
||||
model: request.modelName,
|
||||
temperature: request.temperature,
|
||||
top_p: request.topP,
|
||||
...buildMaxTokensParam(request), // Note: solution around models using different underlying max tokens properties
|
||||
}
|
||||
|
||||
// Add response format if specified (only on final iteration to avoid conflicts with tool calls)
|
||||
@@ -116,7 +131,7 @@ export async function mcpInference(
|
||||
const modelResponse = assistantMessage?.content
|
||||
const toolCalls = assistantMessage?.tool_calls
|
||||
|
||||
core.info(`Model response: ${modelResponse || 'No response content'}`)
|
||||
core.debug(`Model response: ${modelResponse || 'No response content'}`)
|
||||
|
||||
messages.push({
|
||||
role: 'assistant',
|
||||
@@ -181,16 +196,14 @@ async function chatCompletion(
|
||||
try {
|
||||
response = JSON.parse(response)
|
||||
} catch (e) {
|
||||
const preview = response.slice(0, 400)
|
||||
throw new Error(
|
||||
`${context}: Chat completion response was a string and not valid JSON (${(e as Error).message}). Preview: ${preview}`,
|
||||
`${context}: Chat completion response was a string and not valid JSON (${(e as Error).message})`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (!response || typeof response !== 'object' || !('choices' in response)) {
|
||||
const preview = JSON.stringify(response)?.slice(0, 800)
|
||||
throw new Error(`${context}: Unexpected response shape (no choices). Preview: ${preview}`)
|
||||
throw new Error(`${context}: Unexpected response shape (no choices)`)
|
||||
}
|
||||
|
||||
return response as OpenAI.Chat.Completions.ChatCompletion
|
||||
|
||||
15
src/main.ts
15
src/main.ts
@@ -48,19 +48,25 @@ export async function run(): Promise<void> {
|
||||
|
||||
// Get common parameters
|
||||
const modelName = promptConfig?.model || core.getInput('model')
|
||||
let maxTokens = promptConfig?.modelParameters?.maxTokens ?? core.getInput('max-tokens')
|
||||
|
||||
if (typeof maxTokens === 'string') {
|
||||
maxTokens = parseInt(maxTokens, 10)
|
||||
}
|
||||
// Parse token limit inputs
|
||||
const maxCompletionTokensInput =
|
||||
promptConfig?.modelParameters?.maxCompletionTokens ?? core.getInput('max-completion-tokens')
|
||||
const maxCompletionTokens = maxCompletionTokensInput ? Number(maxCompletionTokensInput) : undefined
|
||||
|
||||
const maxTokensInput = promptConfig?.modelParameters?.maxTokens ?? core.getInput('max-tokens')
|
||||
const maxTokens = maxCompletionTokens != null ? undefined : maxTokensInput ? Number(maxTokensInput) : undefined
|
||||
|
||||
const token = process.env['GITHUB_TOKEN'] || core.getInput('token')
|
||||
if (token === undefined) {
|
||||
throw new Error('GITHUB_TOKEN is not set')
|
||||
}
|
||||
core.setSecret(token)
|
||||
|
||||
// Get GitHub MCP token (use dedicated token if provided, otherwise fall back to main token)
|
||||
const githubMcpToken = core.getInput('github-mcp-token') || token
|
||||
core.setSecret(githubMcpToken)
|
||||
|
||||
const githubMcpToolsets = core.getInput('github-mcp-toolsets')
|
||||
|
||||
const endpoint = core.getInput('endpoint')
|
||||
@@ -85,6 +91,7 @@ export async function run(): Promise<void> {
|
||||
temperature,
|
||||
topP,
|
||||
maxTokens,
|
||||
maxCompletionTokens,
|
||||
endpoint,
|
||||
token,
|
||||
customHeaders,
|
||||
|
||||
@@ -96,7 +96,7 @@ export async function connectToGitHubMCP(token: string, toolsets?: string): Prom
|
||||
* Execute a single tool call via GitHub MCP
|
||||
*/
|
||||
export async function executeToolCall(githubMcpClient: Client, toolCall: ToolCall): Promise<ToolResult> {
|
||||
core.info(`Executing GitHub MCP tool: ${toolCall.function.name} with args: ${toolCall.function.arguments}`)
|
||||
core.debug(`Executing GitHub MCP tool: ${toolCall.function.name} with args: ${toolCall.function.arguments}`)
|
||||
|
||||
try {
|
||||
const args = JSON.parse(toolCall.function.arguments)
|
||||
@@ -106,7 +106,7 @@ export async function executeToolCall(githubMcpClient: Client, toolCall: ToolCal
|
||||
arguments: args,
|
||||
})
|
||||
|
||||
core.info(`GitHub MCP tool ${toolCall.function.name} executed successfully`)
|
||||
core.debug(`GitHub MCP tool ${toolCall.function.name} executed successfully`)
|
||||
|
||||
return {
|
||||
tool_call_id: toolCall.id,
|
||||
|
||||
@@ -8,7 +8,8 @@ export interface PromptMessage {
|
||||
}
|
||||
|
||||
export interface ModelParameters {
|
||||
maxTokens?: number
|
||||
maxTokens?: number // Deprecated
|
||||
maxCompletionTokens?: number
|
||||
temperature?: number
|
||||
topP?: number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user