MCPcopy Create free account
hub / github.com/Effect-TS/effect / ToolResultPart

Function ToolResultPart

packages/effect/src/unstable/ai/Response.ts:1645–1696  ·  view source on GitHub ↗
(
  name: Name,
  success: Success,
  failure: Failure
)

Source from the content-addressed store, hash-verified

1643 }
1644 >
1645> = <
1646 const Name extends string,
1647 Success extends Schema.Constraint,
1648 Failure extends Schema.Constraint
1649>(
1650 name: Name,
1651 success: Success,
1652 failure: Failure
1653) => {
1654 const ResultSchema = Schema.Union([success, failure])
1655 const Common = {
1656 id: Schema.String,
1657 type: Schema.Literal("tool-result"),
1658 isFailure: Schema.Boolean,
1659 name: Schema.Literal(name)
1660 }
1661 const Decoded = Schema.Struct({
1662 ...Common,
1663 [PartTypeId]: Schema.Literal(PartTypeId),
1664 result: ResultSchema,
1665 providerExecuted: Schema.Boolean,
1666 metadata: ProviderMetadata,
1667 encodedResult: Schema.toEncoded(ResultSchema),
1668 preliminary: Schema.Boolean
1669 })
1670 const Encoded = Schema.Struct({
1671 ...Common,
1672 result: Schema.toEncoded(ResultSchema),
1673 providerExecuted: Schema.optional(Schema.Boolean),
1674 metadata: Schema.optional(ProviderMetadata),
1675 preliminary: Schema.optional(Schema.Boolean)
1676 })
1677 return Decoded.pipe(Schema.encodeTo(
1678 Encoded,
1679 SchemaTransformation.transform({
1680 decode: (encoded) => ({
1681 ...encoded,
1682 [PartTypeId]: PartTypeId,
1683 providerExecuted: encoded.providerExecuted ?? false,
1684 metadata: encoded.metadata ?? {},
1685 encodedResult: encoded.result,
1686 preliminary: encoded.preliminary ?? false
1687 }),
1688 encode: identity
1689 })
1690 )).annotate({ identifier: `ToolResultPart(${name})` }) satisfies Schema.Codec<
1691 ToolResultPart<Name, Success["Type"], Failure["Type"]>,
1692 ToolResultPartEncoded,
1693 Success["EncodingServices"] | Failure["EncodingServices"],
1694 Success["DecodingServices"] | Failure["DecodingServices"]
1695 >
1696}
1697
1698/**
1699 * Constructs a new tool result part.

Callers 3

AllPartsFunction · 0.70
PartFunction · 0.70
StreamPartFunction · 0.70

Calls 3

annotateMethod · 0.65
pipeMethod · 0.65
transformMethod · 0.65

Tested by

no test coverage detected