Skip to content

[NO-REF] - introduce pia http module#449

Open
vladconstructor wants to merge 5 commits into
Constructor-io:masterfrom
vladconstructor:NO-REF/introduce-pia-http-module
Open

[NO-REF] - introduce pia http module#449
vladconstructor wants to merge 5 commits into
Constructor-io:masterfrom
vladconstructor:NO-REF/introduce-pia-http-module

Conversation

@vladconstructor
Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings May 1, 2026 16:27
@vladconstructor vladconstructor requested a review from a team as a code owner May 1, 2026 16:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a new Product Insights Agent (PIA) HTTP module to the ConstructorIO client, including TypeScript typings and mocha specs, and exposes it as constructorio.pia.

Changes:

  • Added src/modules/pia.js with getSuggestedQuestions and getAnswerResults API methods.
  • Exposed the new module via src/constructorio.js and updated TypeScript declarations to include pia.
  • Added mocha specs for the new PIA module.

Reviewed changes

Copilot reviewed 3 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/types/pia.d.ts Adds TypeScript declarations for the new Pia module and its request/response types.
src/types/index.d.ts Re-exports Pia types from the types entrypoint.
src/types/constructorio.d.ts Adds pia: Pia to the ConstructorIO type surface and namespace exports.
src/modules/pia.js Implements the Pia HTTP module (URL construction + fetch calls).
src/constructorio.js Instantiates and exposes this.pia on the main client.
spec/src/modules/pia.js Adds mocha coverage for suggested questions + answer results, including timeout cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/modules/pia.js
Comment on lines +7 to +15
const {
apiKey,
clientId,
sessionId,
segments,
userId,
version,
agentServiceUrl,
} = options;
Comment thread src/modules/pia.js Outdated
Comment on lines +98 to +109
const controller = new AbortController();
const { signal } = controller;

try {
requestUrl = createPiaUrl(itemId, parameters, this.options, '');
} catch (e) {
return Promise.reject(e);
}

helpers.applyNetworkTimeout(this.options, networkParameters, controller);

return fetch(requestUrl, { signal })
Comment thread src/modules/pia.js
Comment on lines +140 to +145
getAnswerResults(itemId, question, parameters, networkParameters = {}) {
let requestUrl;
const { fetch } = this.options;
const controller = new AbortController();
const { signal } = controller;

@vladconstructor vladconstructor marked this pull request as draft May 7, 2026 13:56
@vladconstructor vladconstructor marked this pull request as ready for review May 12, 2026 18:03
@vladconstructor
Copy link
Copy Markdown
Contributor Author

@claude

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 6 changed files in this pull request and generated 1 comment.

Comment thread spec/src/modules/pia.js
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 8 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Contributor

@esezen esezen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, I left some small comments.

Comment thread src/modules/pia.js
Comment on lines +160 to +162
if (!question || typeof question !== 'string') {
return Promise.reject(new Error('question is a required parameter of type string'));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this up to come before AbortController so that we never even instantiate the AbortController if the question is not valid?

Comment thread src/modules/pia.js
return json;
}

throw new Error('getSuggestedQuestions response data is malformed');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test to check for this case?

Comment thread src/modules/pia.js
}

if (parameters) {
const { threadId, variationId, numResults } = parameters;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the tests to check for threadId?

Comment thread src/modules/pia.js
queryParams.variation_id = variationId;
}

if (!helpers.isNil(numResults)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, can we test this in one of the tests?

Comment thread src/types/pia.d.ts
}

export interface PiaAnswerItemResults {
request?: Record<string, any>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually very loose or do we know the shape of this? If we do, can we type it strictly? I know we have Record<string, any> in other parts of the library but we are trying to move away from that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants