# context.plugins

消费方先在 [dependencies](./manifest.md#manifest-dependencies) 中声明包版本范围，并在 [uses](./services.md#serviceuse) 中声明提供方、服务 ID 和版本。提供方已启用且服务版本匹配时，就可以调用其方法。完整项目见[服务示例](../guides/examples.md#运行服务示例)。

## call()

向服务提供方发送一次调用。

```ts
context.plugins.call<Result = unknown>(pluginId: string, serviceId: string,
  method: string, args?: Record<string, unknown>): Promise<Result>
```

### 参数

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| `pluginId` | `string` | 服务提供方的插件 ID。 |
| `serviceId` | `string` | 提供方声明的服务 ID。 |
| `method` | `string` | 服务声明的方法名。 |
| `args` | `Record<string, unknown>` | 传给服务处理函数的 JSON 对象，默认 `{}`。 |

### 返回值

Promise 解析为提供方的返回值。提供方未启用、版本不匹配或方法执行失败时，Promise 拒绝。参数和结果默认各最多 4 KiB；提供方可通过 Service.maxBytes 声明 1024–65536 字节上限。

### 示例

```js
const result = await context.plugins.call(
  "example.service-provider", "numbers", "sum", { values: [1, 2, 3] }
);
return result;
```
