Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sdks/ts/packages/golem-ts-sdk/src/decorators/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export function agent(options?: AgentDecoratorOptions) {

const agentConfigEntries = Either.getOrThrowWith(
getAgentConfigEntries(classMetadata.constructorArgs),
(err) => new Error(`Failed to describe agent config: ${err}`),
(err) => new Error(`Failed to describe config for agent \`${agentTypeName.value}\`: ${err}`),
);

const agentType: AgentType = {
Expand Down Expand Up @@ -434,7 +434,9 @@ function getAgentConfigEntries(
TypeScope.object(param.name, prop.path.at(-1)!, prop.type.optional),
);
if (Either.isLeft(witTypeEither)) {
return Either.left(`config property \`${prop.path.join('.')}\`: ${witTypeEither.val}`);
return Either.left(
`parameter \`${param.name}\`, config property \`${prop.path.join('.')}\`: ${witTypeEither.val}`,
);
}

const configSource: AgentConfigSource = prop.secret ? 'secret' : 'local';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ function serializeRpcConfigObject(
const result: TypedAgentConfigValue[] = [];

if (rpcValue === null || typeof rpcValue !== 'object') {
throw new Error('rpcValue must be an object');
throw new Error(
`Expected an object for config parameter \`${configProperties[0]?.path[0] ?? 'config'}\`, got ${typeof rpcValue}`,
);
}

for (const prop of configProperties) {
Expand Down Expand Up @@ -563,7 +565,10 @@ function serializeRpcConfigObject(

const [witType, analysedType] = Either.getOrThrowWith(
WitType.fromTsType(expectedType, undefined),
(err) => new Error(`Failed to construct analysed type for rpc agent config: ${err}`),
(err) =>
new Error(
`Failed to construct type for rpc config property \`${prop.path.join('.')}\`: ${err}`,
),
);

const witValue = WitValue.fromTsValueDefault(current, analysedType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const handlers: { [K in TsType['kind']]: Handler<K> } = {
others: handleOthers,
'unresolved-type': handleUnresolved,
array: handleArray,
config: unsupportedWithHint('Config', 'Use a plain type literal instead.'),
config: unsupportedWithHint('Config', 'Use an inline object type instead.'),
principal: handlePrincipal,
'quota-token': handleQuotaToken,
};
Expand Down
4 changes: 2 additions & 2 deletions sdks/ts/packages/golem-ts-sdk/tests/invalid.agents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ test('Agent with unsupported type in config field is rejected with path in error
await expect(async () => {
await import('./agentWithInvalidConfig');
}).rejects.toThrowError(
'Failed to describe agent config: config property `unsupported`: Unsupported type `class` in config for parameter `unsupported`. Hint: Use object instead.',
'Failed to describe config for agent `AgentWithInvalidConfig`: parameter `config`, config property `unsupported`: Unsupported type `class` in config for parameter `unsupported`. Hint: Use object instead.',
);
});

Expand All @@ -319,7 +319,7 @@ test('Config type used as a field inside another Config produces a helpful error
expect(Either.isLeft(result)).toBe(true);
assert(Either.isLeft(result));
expect(result.val).toBe(
'Unsupported type `Config` in myConfig for parameter `nested`. Hint: Use a plain type literal instead.',
'Unsupported type `Config` in myConfig for parameter `nested`. Hint: Use an inline object type instead.',
);
});

Expand Down
4 changes: 2 additions & 2 deletions sdks/ts/packages/golem-ts-typegen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ function getTypeFromTsMorphInternal(

const typeLiteral = resolveStrictTypeLiteralNode(innerType);
if (typeLiteral == null)
throw `Config<T> type parameter must be a plain type literal (e.g. Config<{ key: string }>), got: ${innerType.getText()}`;
throw `Config<T> type parameter must be an inline object type (e.g. Config<{ key: string }>), got: ${innerType.getText()}`;

const result = extractConfigPropertiesFromTypeLiteral(typeLiteral, [], wellKnownTypes);
if (result == null)
throw 'Config<T> type literal must only contain property signatures. Method signatures and index signatures are not supported.';
throw 'Config<T> must be an object type with only property signatures. Method signatures and index signatures are not supported.';

return {
kind: 'config',
Expand Down
Loading