# Main

Main是一個靜態方法，主要是基於管理的語法糖，使用方法如下：

{% hint style="info" %}
以下的範例可能有點抽象，你可以直接參考[API Service](/application/api-service.md)來了解其運作概念。
{% endhint %}

```typescript
const Order = require('packhouse/plugins/order')
const Packhouse = require('packhouse')

let main = Packhouse.Main((packhouse, event) => {
    // 可以傳遞參數
    console.log(event.hello) // world
    // 可以定義事件
    packhouse.on('run', () => { ... })
    // 回傳基本資料
    return {
        plugins: [
            Order
        ],
        groups: {
            'math': () => {
                return {
                    data: require('./math'),
                    options: {}
                }
            }
        },
        mergers: {
            'myMerger': () => {
                return {
                    data: require('./myMerger'),
                    options: {}
                }
            }
        }
    }
})

let packhouse = main({
    hello: 'world'
})

packhouse.tool('math/sum').action(...)
```

## TypeScript

如果你使用TypeScript，可以使用我們提供的Declaration File：

```typescript
import { Main } from 'packhouse/types'

const Main: Main = Packhouse.Main
const main = Main(() => ({})
const packhouse = main()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://packhouse-doc.metalsheep.com/the-instance/main.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
